【问题标题】:Google Maps API v3 calculate distance ,duration SynchronouslyGoogle Maps API v3 同步计算距离、持续时间
【发布时间】:2010-12-09 11:54:51
【问题描述】:

有什么方法可以同步在 google maps v3 中计算距离和持续时间?我想做一个函数,它需要 2 个参数(latLng,latLng)并返回它们之间的距离(不是直线,而是通过道路)(或持续时间)。

【问题讨论】:

  • 无法同步执行此操作。为什么要求这必须是同步的?

标签: javascript ajax google-maps google-maps-api-3


【解决方案1】:

您不需要谷歌。你需要Haversine formula:

R = earth’s radius (mean radius = 6,371km)
Δlat = lat2 − lat1
Δlong = long2 − long1
a = sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlong/2)
c = 2 * atan2(√a, √(1−a))
d = R * c 

【讨论】:

  • 我知道haversine公式,但我不想计算直线距离,我想通过道路计算它。
  • 那没关系。也许您想在您的问题中添加 small 细节?
猜你喜欢
  • 2015-02-18
  • 1970-01-01
  • 2012-03-25
  • 2017-04-09
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多