How to get total travelled distance and route from google map directions api like uber

微笑、不失礼 提交于 2019-12-08 13:11:46

问题


How to get total travelled distance and route from google map directions API to show user travelled path like Uber.


回答1:


You can use the Google Maps Distance Matrix API that provides travel distance and time for a matrix of origins and destinations. It returns information based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair.

A Google Maps Distance Matrix API request takes the following form: https://maps.googleapis.com/maps/api/distancematrix/outputFormat?parameters where outputFormat may be either of the following values:

  • json (recommended), indicates output in JavaScript Object Notation (JSON); or
  • xml, indicates output as XML.

Check this example from GitHub. The tutorial finds the distance and time taken to travel in driving mode and by avoiding tolls from origin to destination using Google Maps Distance Matrix API.

Here also are some related SO questions:

  • How to get total driving distance with Google Maps API V3?
  • Using Google Maps API to get travel time data

Hope this helps!



来源:https://stackoverflow.com/questions/38184473/how-to-get-total-travelled-distance-and-route-from-google-map-directions-api-lik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!