Google 地图 - 如何获取两点之间的距离(以米为单位)?
我有这些坐标:
(45.463688, 9.18814)
(46.0438317, 9.75936230000002)
并且我需要(我认为通过 Google API V3)来获取这两个点之间的距离(以米为单位)。我该怎么做呢?
I have these coordinate :
(45.463688, 9.18814)
(46.0438317, 9.75936230000002)
and I need (trought Google API V3, I think) to get the distance between those 2 points in metre. How can I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您想使用 v3 谷歌地图 API,可以使用以下函数:
注意:您必须将
&libraries=geometry
添加到脚本源中If you're looking to use the v3 google maps API, here is a function to use:
Note: you must add
&libraries=geometry
to your script source我认为你可以不需要任何特定的API,并使用简单的Javascript计算距离:
This< /a> 网站提供了有关地理计算和用于距离计算的 Javascript 示例的良好信息。
好吧,快速浏览一下 Google API 页面,看来您可以通过以下方式做到这一点:
I think you could do without any specific API, and calculate distance with plain Javascript:
This site has good info about geographical calculations and Javascript sample for distance calculation.
Ok, quick glance at Google API page and it seems, you could do it by:
http://www.csgnetwork.com/gpsdistcalc.html
与编码无关
编辑
如果您正在寻找一些代码
计算中两点之间的距离谷歌地图V3
http://www.csgnetwork.com/gpsdistcalc.html
Has nothing to do with coding btw
EDIT
if you're looking for some code
Calculate distance between two points in google maps V3
这主要是通过 google api 之外的数学来完成的,因此除了查找正确的坐标之外,您不需要使用该 API 进行任何操作。
了解了这一点,这里有一个之前回答过的与 Javascript 相关的问题的链接。
计算 2 个 GPS 坐标之间的距离
This is primarily done with math outside of the google api, so you shouldn't need to use the API for anything other than finding the correct coordinates.
Knowing that, here's a link to a previously answered question relating to Javascript.
Calculate distance between 2 GPS coordinates
试试这个
Try this
试试这个:
参考文献:http://www.movable-type.co.uk /scripts/latlong.html
Try this:
References: http://www.movable-type.co.uk/scripts/latlong.html
您指的是整个路径长度的距离还是只想知道位移(直线距离)?我发现没有人指出这里距离和位移之间的区别。对于距离计算由 JSON/XML 数据给出的每个路线点,对于位移,有一个使用
Spherical
类的内置解决方案。Are you referring to distance as in length of the entire path or you want to know only the displacement (straight line distance)? I see no one is pointing the difference between distance and displacement here. For distance calculate each route point given by JSON/XML data, as for displacement there is a built-in solution using
Spherical
class.您指的是整个路径长度的距离还是只想知道位移(直线距离)?我发现没有人指出这里距离和位移之间的区别。对于距离计算由 JSON/XML 数据给出的每个路线点,对于位移,有一个使用
Spherical
类的内置解决方案。这个想法是,如果您指的是距离,那么您只需在每个路径点上使用computeDistanceBetween并将其连接起来。Are you referring to distance as in length of the entire path or you want to know only the displacement (straight line distance)? I see no one is pointing the difference between distance and displacement here. For distance calculate each route point given by JSON/XML data, as for displacement there is a built-in solution using
Spherical
class. The idea is if your are referring to distance then you just use thecomputeDistanceBetween
on each path point and concatenate it.