Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google MAP API: How to draw shortest plane path between two geo-points?

I need to draw shortest plane path on a map. I created KML in Google Earth and loaded int to Google Map. As you can see attached images: paths is very different: Google Vap path is longer. How to draw arc path on Google map?

Path in Google EarthSame path in Google Map

like image 302
Alexey Ryazhskikh Avatar asked Jun 09 '12 08:06

Alexey Ryazhskikh


People also ask

How do I get the shortest route on Google Maps API?

To obtain the shortest route from A to B I would suggest to make different queries with the “alternatives=true” parameter, playing with the “avoid” parameter between avoid=toll, avoid=highways, and then I would compare all results to pick the shortest route.

Can Google Maps API calculate distance between two points?

What can you do with the Distance Matrix API? The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic.


1 Answers

In V3, it's simply adding the geodesic: true option to your Polyline.

Demo http://jsfiddle.net/yV6xv/20/ Click on the map to define path endpoints

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

    var path = [];

    google.maps.event.addListener(map, 'click', function(event) {
      new google.maps.Marker({map:map,position:event.latLng});
      path.push(event.latLng);
      myLine.setPath(path);
    });

result from demo

like image 104
Tina CG Hoehr Avatar answered Sep 20 '22 01:09

Tina CG Hoehr