I'm having trouble tracing.
I have 2 inputs text, with google's auto completion function.
When the user dials the second input. The map already traces the route between the two points.
But I want to make a modification, and I'm in trouble.
I want to change the second point, for several button radios.
Then the user will dial the radio button, and when typing the location in the input text, will trace the route automatically.
Here is the part of the code where it autocompletes the field, and traces the route:
origin_autocomplete.addListener('place_changed', function() {
var place = origin_autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}
expandViewportToFitPlace(map, place);
// If the place has a geometry, store its place ID and route if we have
// the other place ID
origin_place_id = place.place_id;
route(origin_place_id, destination_place_id, travel_mode, directionsService, directionsDisplay);
});
destination_autocomplete.addListener('place_changed', function() {
var place = destination_autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}
expandViewportToFitPlace(map, place);
// If the place has a geometry, store its place ID and route if we have
// the other place ID
destination_place_id = place.place_id;
route(origin_place_id, destination_place_id, travel_mode, directionsService, directionsDisplay);
});
function route(origin_place_id, destination_place_id, travel_mode,directionsService, directionsDisplay) {
if (!origin_place_id || !destination_place_id) {
return;
}
directionsService.route({
origin: {'placeId': origin_place_id},
destination: {'placeId': destination_place_id}, travelMode: travel_mode
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
I get the position of the radio button like this:
positionMarkerSelected = markersArray[indiceAux].getPosition();
And I tried to substitute direct in the function that traces the route:
directionsService.route({
origin: {'placeId': origin_place_id},
destination: positionMarkerSelected , travelMode: travel_mode
}
But it does not work, does anyone know how to solve this?