javascript Google MAP API v3:以公制形式计算的computeDistanceBetween 方法和距离

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6601122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:14:23  来源:igfitidea点击:

Google MAP API v3: computeDistanceBetween method and distance in metric form

javascriptgoogle-maps-api-3

提问by Hellnar

I want to calculate the direct distance between to positions in metric form. (ie: from A to B in kilometers).

我想以公制形式计算位置之间的直接距离。(即:从 A 到 B,以公里为单位)。

I didn't understand what computeDistanceBetweenmethod returns in units.

我不明白computeDistanceBetween方法以单位返回什么。

Thanks

谢谢

回答by katspaugh

It's in meters. To convert to kilometers divide by 10241000, obviously.

它以米为单位。转换为公里除以10241000,显然.

google.maps.geometry.spherical.computeDistanceBetween(
    Moscow, Leningrad
); // 679601 m

By the way, the underlying code of this library method is based on the Haversine formula.

顺便说一下,这个库方法的底层代码是基于Haversine公式的