我有一个带有 latlang 值的数组,我想绘制一个遵循这个值的路径。这就是我所做的,但它只画到某个点。当我 console.log '结果'时,期待绘制的对象,它会打印
Uncaught Error: Error in property <routes>: (Cannot read property 'routes' of null)
function renderDirections(result) {
var directionDisplay = new google.maps.DirectionsRenderer();
directionDisplay.setMap(map);
directionDisplay.setDirections(result);
directionDisplay.setOptions({suppressMarkers: true});
}
for(var i=0; i < array.length; i++){
var marker = new google.maps.Marker({
position: new google.maps.LatLng(array[i].lat, array[i].lng),
map: map
});
var directionsService = new google.maps.DirectionsService();
directionsService.route({
origin: new google.maps.LatLng(array[i].lat, array[i].lng),
destination: new google.maps.LatLng(array[i+1].lat, array[i+1].lng),
unitSystem: google.maps.UnitSystem.IMPERIAL,
travelMode: google.maps.DirectionsTravelMode.DRIVING
},
function(result){
renderDirections(result);
});
}