简体   繁体   中英

Get distance of each country in Google Maps (Angular)

I use AgmCoreModule and AgmDirectionModule in my Angular project. I want to draw a route between points A, B, C which goes through different countries. I want to know how many kilometers of route are in each country separately. Is it possible? Or should you use some different library?

If you want to calculate the distance in a straight line (like a plane) but with the curvature of the earth/elevation considered, I think @turf/distance is a good option.

If you want to calculate through a path on a map (with streets and such, literally going from A to B), you'll have to use the google maps directions API: https://developers.google.com/maps/documentation/directions/intro

AGM has a certain implementation which is third party and a bit fishy:

https://www.npmjs.com/package/agm-direction

I have used it successfully in the past.

Otherwise you can use google's official sdk:

https://github.com/googlemaps/google-maps-services-js

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