【问题标题】:Google map show different distance between two dastination谷歌地图显示两个目的地之间的不同距离
【发布时间】:2023-03-06 17:41:01
【问题描述】:

我正在创建一个窗口窗体应用程序,它使用谷歌 API 通过它们的 Lat-Long 计算两个位置之间的距离。这很好用,但我注意到有时 api 会为相同的位置给出不同的结果(距离)。

示例:-

位置-A => 孟买 (19.075983 , 72.877655)

位置-B => 德里 (28.704060 , 77.102493)

当我计算从 location-Alocation-B

的距离时
decimal Distance = EmployeeTaskWorkLogManager.getDistance(string.Concat(19.075983, ", ", 72.877655), string.Concat(28.704060, ", ", 77.102493));

这表明 距离 = 1423.297

当我计算从 location-Blocation-A

的距离时
decimal Distance = EmployeeTaskWorkLogManager.getDistance(string.Concat(28.704060, ", ", 77.102493), string.Concat(19.075983, ", ", 72.877655));

这表明 距离 = 1415.239

这是我用来计算两个位置之间距离的代码,

 public static decimal getDistance(string origin, string destination)
        {
            decimal num;
            Thread.Sleep(1000);
            decimal num1 = new decimal(0);
            string[] strArrays = new string[] { "https://maps.googleapis.com/maps/api/distancematrix/json?origins=", origin, "&destinations=", destination, "&key=****" };
            string str = string.Concat(strArrays);
            JObject jObjects = JObject.Parse(EmployeeTaskWorkLogManager.fileGetContents(str));
            try
            {
                num1 = (decimal)jObjects.SelectToken("rows[0].elements[0].distance.value");
                num = num1 / new decimal(1000);
            }
            catch
            {
                num = num1;
            }
            return num;
        }

我检查了我的代码的每一行,但无法找到为什么会出现这种差异。

【问题讨论】:

  • 你在谷歌地图上查看这个距离
  • 是的,现在我检查了谷歌地图,我震惊了谷歌地图也显示了差异。有人知道为什么谷歌地图会显示这种差异吗?
  • 您不应在您的代码中在线发布您的私人 Google API 密钥...

标签: c# .net google-maps google-maps-api-3 google-maps-api-2


【解决方案1】:

Google 地图距离矩阵 API 不会计算两点之间的直线距离或大圆距离。相反,它会根据出行方式返回距离(您尚未在 API 调用中指定,因此默认为 driving)。 想一想:您不可能在两个方向上行驶准确的距离,而且路程越长,需要的路线变​​化越多,差异就会越明显。这将取决于高速公路的匝道(在两个方向的特定交叉路口均不可用)、单向街道等。

因此,结果符合预期。

来源:Google Maps Distance Matrix API

【讨论】:

    猜你喜欢
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 2016-07-08
    • 2011-09-21
    • 2010-12-02
    相关资源
    最近更新 更多