Alexey Ryazhskikh
Alexey Ryazhskikh

Reputation: 2500

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 Earth Same path in Google Map

Upvotes: 6

Views: 6514

Answers (2)

Tina CG Hoehr
Tina CG Hoehr

Reputation: 6779

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

Upvotes: 10

Marcelo
Marcelo

Reputation: 9407

This example is for the API V2, but the math is the same for V3: http://maps.forum.nu/gm_flight_path.html

Marcelo.

Upvotes: 0

Related Questions