1

I am trying to fetch google distances in gridview RowDataBound with a force sleep of 1000ms,Nothing helping,Am getting correct distance for the first query,ie the first row of the gridview, all others i get 'Over-Query-Limit' for content variable ,I want to know three things:

  • Is there any solution for this situation.
  • Is google limiting queries per day OR
  • Is google limiting queries per second ?
public int getDistance(string origin, string destination)
    {
        System.Threading.Thread.Sleep(1000);
        int distance = 0;
        string url = "http://maps.googleapis.com/maps/api/directions/json?origin=" + origin + "&destination=" + destination + "&sensor=false";
        string requesturl = url;
        string content = fileGetContents(requesturl);
        JObject o = JObject.Parse(content);
        try
        {
            distance = (int)o.SelectToken("routes[0].legs[0].distance.value");
            return distance;
        }
        catch
        {
            return distance;
        }
        return distance;
    }
sajanyamaha
  • 3,119
  • 2
  • 26
  • 44
  • Just read the official [google maps API licensing page](https://developers.google.com/maps/licensing) – lurkerbelow Oct 27 '12 at 10:21
  • @lurkerbelow : It says 2500 per day,but then how come am getting the first query output if 2500 is over ?Also it does not tell anything about per second limitations . – sajanyamaha Oct 27 '12 at 10:26
  • have you read [geocoding-api-query-over-limit](http://stackoverflow.com/questions/9805529/geocoding-api-over-query-limit)? some people do report that they have the same issue as you, there's a workaround provided in that link. – lurkerbelow Oct 27 '12 at 10:28
  • yes i had tried 1000ms delay,no help,They are even advicing to ditch google,i strongly think there is some other proper workaround. – sajanyamaha Oct 27 '12 at 10:32

1 Answers1

-1

Ok,As above 2500 queries per day makes google search a paid service i went for another logic,We can calculate distances without google.com as follows :

    public decimal calcDistance(decimal latA, decimal longA, decimal latB, decimal longB)
    {

        double theDistance = (Math.Sin(DegreesToRadians(latA)) *
                Math.Sin(DegreesToRadians(latB)) +
                Math.Cos(DegreesToRadians(latA)) *
                Math.Cos(DegreesToRadians(latB)) *
                Math.Cos(DegreesToRadians(longA - longB)));

        return Convert.ToDecimal((RadiansToDegrees(Math.Acos(theDistance)))) * 69.09M * 1.6093M;
    }

    public double DegreesToRadians(decimal degrees)
    {
        return Convert.ToDouble((Convert.ToDecimal(Math.PI) / 180.0M) * degrees);
    }

    public double RadiansToDegrees(double radians)
    {
        return Convert.ToDouble((180.0M / Convert.ToDecimal(Math.PI)) * Convert.ToDecimal(radians));
    }
sajanyamaha
  • 3,119
  • 2
  • 26
  • 44
  • 3
    But there is difference between the two distances (Google vs Yours): one is actual walking/driving distance by HUMAN and other is AS-CROW-FLIES – Rohit May 03 '13 at 14:12