简体   繁体   English

如何使用Google Maps API计算两个以上的点之间的距离?

[英]How to calculate distance between more than two points with google maps api?

Calculating distance between two point with google maps is easy and I did. 用谷歌地图计算两点之间的距离很容易,我做到了。 But how to calculate distance between more then two marks in google map with the help of google maps api? 但是,如何借助Google Maps API计算Google地图中两个以上标记之间的距离?

This is quite a broad use-case, But for a simple solution of your question I would recommend you using a Distance Matrix API . 这是一个相当广泛的用例,但是对于您的问题的简单解决方案,我建议您使用Distance Matrix API This would help you to find distances in between two or even more cities. 这将帮助您找到两个或更多城市之间的距离。 The API request to find the distance in between 4 cities would be like this. 查找4个城市之间距离的API请求将像这样。

https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&key=API_KEY

This request will return four elements - two origins times two destinations: 该请求将返回四个元素-两个起点乘以两个终点:

Vancouver to San Francisco, Vancouver to Victoria, Seattle to San Francisco & Seattle to Victoria 温哥华到旧金山,温哥华到维多利亚,西雅图到旧金山和西雅图到维多利亚

Please take a look at the official Google Documentation of Distance Matrix API to know more about the API requests for more origins and destination. 请查看距离矩阵 API的官方Google文档,以了解有关更多起点和终点的API请求的更多信息。

One more option for you is to use a Direction API , but that would cover points in a path and there respective distance. 您还可以选择使用Direction API ,但这将覆盖路径中的点以及相应的距离。

Hope that Helps!! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM