简体   繁体   中英

How to get the total driving distance with Google Distance Matrix API?

I have an array of lat/lng. Example:

[
  "14.60592,103.12081",
  "38.21146,114.86461",
  "13.73028,100.65138",
  "34.08863,108.39783",
  "57.186,14.04"
]

How can I calculate the overall distance from A to B and from B to C.

I trying with the Google Distance Matrix API.

If you need driving distance then you will not be able to calculate it with any formula not knowing the terrain, roads etc. For example if there is a river between those two points then the driving distance will depend on where is the closest bridge.

You can use some API that has that knowledge and can give you a real driving distance. For example you can use the Google Maps API. See eg Distance Matrix API:

You can use the Google Maps API in Node with:

and some more - see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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