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?
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.
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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With