我需要在地图上绘制最短平面路径。我在Google Earth中创建了KML文件,并将其加载到Google Map中。如您所见,附加的图片显示路径非常不同:Google Vap路径更长。如何在Google地图上绘制弧线路径?
在V3中,只需在你的折线上添加geodesic: true
选项即可。
Demo http://jsfiddle.net/yV6xv/20/ 点击地图以定义路径端点。
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);
});