1

我正在尝试以1000 毫秒的强制睡眠在gridview RowDataBound中获取 google 距离,没有任何帮助,我正在为第一个查询获得正确的距离,即 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;
    }
4

1 回答 1

-1

好的,由于每天超过 2500 次查询使 google 搜索成为付费服务,我采用了另一种逻辑,我们可以在没有 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));
    }
于 2012-10-29T06:35:14.463 回答