So I am working on the direction service using Google Map API. The site works fine with the autocomplete service and I am trying to add the text panel telling users how to get to the destination using 'transit', 'walking', and 'driving' mode.
https://jsfiddle.net/QPX321/yo4tbh58/
what to do is to have the text giving routing information based on the travel mode users select. say if I select 'transit' it shows me the bus that I have to take.
so I know something is wrong with my code in the function below.
function calculateAndDisplayRoute(directionsService,
directionsDisplay) {
var start = document.getElementById('origin-input').value;
var end = document.getElementById('destination-input').value;
var modeSelector = document.getElementById('mode-selector');
directionsService.route({
origin: start,
destination: end,
travelMode: modeSelector,
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
the code works fine when I change
travelMode: modeSelector,
to
travelMode: 'WALKING', or
travelMode: 'DRIVING', or
travelMode: 'DRIVING',
but this will only give one option and it forcibly change my travel mode to one specific mode. How should I code it so the text panel is able to detect my travel mode, hence giving my the appropriate suggestion?
i think the problem is that I did not link my travel mode to the function? I use the code below to set my travel mode,
var modeSelector = document.getElementById('mode-selector');
and thought the code below would be able to detect my travel mode
travelMode: modeSelector,
but it did not work when I use these code.
I would expect the text panel to show direction in the travel mode that I click. If I click driving mode, it should give me direction on how to drive from point A to point B. The code does not give me any text unless I change the travelMode: to a specific mode ('driving', 'transit', or 'walking').
Thank you in advance for you help and precious time.
Regards,