Google Maps - calculate lines and distance (like crows) between several latitudinal pairs of longitude

I am looking to build a “like a crow” route on a map across several latitudinal latitudes. I also need to calculate the total distance (and the preferred distance between points).

I found this example http://www.daftlogic.com/projects-advanced-google-maps-distance-calculator.htm , but it is much more complicated than I require - I don’t need any search functions since I have There is already data on the latitude of longitude. However, the way to display the route is what I am looking to achieve

Are there any simpler examples that I can use or any general recommendations for achieving this?

+4
source share
3 answers

Building a crow-like route is easy, just set the polyline parameter to a geodesic value of true:

var geodesic = new google.maps.Polyline({geodesic: true}); 

You can use this example: http://code.google.com/apis/maps/documentation/javascript/examples/geometry-headings.html

To calculate the distance, you can use the Google Maps API V3 geometry library. http://code.google.com/apis/maps/documentation/javascript/geometry.html

The calculation is simple:

 var distance = google.maps.geometry.spherical.computeDistanceBetween(latLngOfPointA, latLngOfPointB); 

To calculate the path length, you can use the computeLength function:

 var path = geodesic.getPath(); var length = google.maps.geometry.spherical.computeLength(path) 
+6
source

Be sure to include geometry in your call in the Google Maps API.

Download from documentation

 <script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true_or_false"> </script> 
+2
source

I have an Excel file with a Vincenty formula that I could forward. Accuracy is better than 20 cm at 20'000 km.

0
source

Source: https://habr.com/ru/post/1343245/


All Articles