0

有谁知道为什么这只是给我 n+1 路线的方向。例如来自 ABCDEF,它会给我以下路线:

AB

BC(空结果)

光盘

DE(空结果)

英孚

这是我的谷歌地图代码,我用(在 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;
        }
    });
}
4

0 回答 0