我正在寻找使用javascript,谷歌地图api v3和pgoruting两点之间的路线。现在我有下面的方法,当我只给一个航点时,它可以正常工作。但是当我不止一个航点的时候它不起作用。有多个航点的格式与此符号'|'
一致。因此,对于例如:36.762121,14.7866553|35.988777778,14.655444333
使用航点找到路线
JavaScript方法如下:
function calcRoute() {
var all_nodes = document.getElementById('result').innerHTML;
var node = all_nodes.split("|");
var start = node[0];
var end = node[node.length - 1];
var wpts = [];
for (var i = 1; i < node.length-1; i++) {
wpts.push({
location:node[i],
stopover:true
});
}
var request = {
origin: start,
destination: end,
waypoints: wpts,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert('No route found');
}
});
}
您是否有一个示例_doesn't_ work?这工作正常:'36.762121,14.7866553 | 35.988777778,14.655444333' – geocodezip 2013-03-03 15:37:26
正如[this](http://www.geocodezip.com/v3_GoogleEx_directions-waypoints_fromString.html):'36.762121,14.7866553 |意大利米兰|瑞士苏黎世| 35.988777778,14.655444333' – geocodezip 2013-03-03 15:46:21
我已经尝试了上面的例子,我已发布的功能,我没有结果。 @geocodezip – 2013-03-03 16:01:39