有谁知道为什么这只给我n + 1路线的路线。例如,从A-B-C-D-E-F,它将给我以下路线:
A-B
B-C(空结果)
C-d
D-E(空结果)
E-F
这是我的谷歌地图代码,我正在调用它(在UIWebView中):
showDirections([A,B,C,D,E],true);
var directionsService = new google.maps.DirectionsService();
function showDirections(locations, metric) {
var units = metric ? google.maps.UnitSystem.METRIC : google.maps.UnitSystem.IMPERIAL;
for (i=0; i<locations.length-1; i++) {
console.log('navigating: '+locations[i].title+' to '+locations[i+1].title);
var request = {
origin: new google.maps.LatLng(locations[i].location.lat, locations[i].location.lng),
destination: new google.maps.LatLng(locations[i+1].location.lat, locations[i+1].location.lng),
travelMode: google.maps.DirectionsTravelMode.DRIVING,
avoidHighways: !!(locations[i].avoidHighway),
unitSystem: units
};
setTimeout(function() { getDirections(request); }, 2000);
}
window.location = 'directionsstatus://LOADED';
}
function renderDirections(directions) {
var directionsDisplay = new google.maps.DirectionsRenderer;
directionsDisplay.setPanel(document.getElementById('panel'));
directionsDisplay.setDirections(directions);
}
function getDirections(request) {
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
renderDirections(response);
} else {
alert(status);
window.location = 'directionsstatus://' + status;
}
});
}