谷歌距离使用C# - Over-Query-Limit

时间:2012-10-27 10:18:57

标签: google-maps

我正在尝试使用强制睡眠1000毫秒来获取 gridview RowDataBound 中的谷歌距离,没有任何帮助,我获得了第一个查询的正确距离,即第一行对于内容变量,对于gridview,所有其他我得到'Over-Query-Limit',我想知道三件事:

  • 这种情况有没有解决办法。
  • 谷歌是否每天限制查询或
  • 谷歌是否每秒限制查询?
 
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;
    }

1 个答案:

答案 0 :(得分:-1)

好的,正如上面每天2500次查询使谷歌搜索成为付费服务我又采用了另一种逻辑,我们可以在没有google.com的情况下计算距离,如下所示:

    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));
    }