【问题标题】:google maps distance calculation issue谷歌地图距离计算问题
【发布时间】:2016-09-23 05:58:00
【问题描述】:

我正在根据我当前的位置从数据库中获取最近的纬度。我的当前位置

      latitude:  32.5033801 
      longitude:  74.49884399999999

我找到了这个表格 https://ctrlq.org/maps/where/ 。我正在使用这个查询

SELECT lat,lng, ( 6371 * acos( cos( radians(32.5033801) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(74.49884399999999) ) + sin( radians(32.5033801) ) * sin( radians( lat ) ) ) ) AS distance FROM stores HAVING distance < 60 ORDER BY distance LIMIT 0 , 20

这个查询让我从当前位置到 Model Town Rd, Gujranwala, Pakistan 的距离为 47.2 公里。但谷歌地图给了我 54.9 公里。现在有大约7公里的差异,我认为这太过分了。

我附上了两张图片,第一张是我的查询结果,第二张是谷歌地图的结果

【问题讨论】:

  • 两个坐标之间的距离有两种,即行距和行车距离,你在计算行距,你需要行车距离。
  • 如何从查询中找到行驶距离
  • 我看到了 58.0 和 68.4,你不也应该抱怨一下吗?
  • 请注意,您必须从 Model Town Rd. 回溯,这可能会消耗 2 公里的差异。然后在目的地附近的路段再行驶 5 公里。

标签: php mysql google-maps google-maps-api-3 latitude-longitude


【解决方案1】:

两个坐标之间有两种距离,即线距行车距离,你在计算线距,你需要行驶距离

这里是帮助你的文档:

https://developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters

这是一个例子:

https://developers.google.com/maps/documentation/javascript/examples/distance-matrix

希望对你有帮助!

【讨论】:

  • 我可以像计算行距一样从数据库计算行驶距离
【解决方案2】:

您的查询计算两点之间的距离。 Google 地图正在为您提供行车路线。

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2016-04-12
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 2011-07-19
    相关资源
    最近更新 更多