-1👍
✅
directionsService.route()
is executed before the Promise is returned. Therefore, the waypts
array is not populated in time.
Solution:
stops.then(function(value) {
directionsService.route({
origin: origin,
destination: dest,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
console.log(response)
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
});
Minimal. Complete. Verifiable.
Source:stackexchange.com