I'd like to draw an itinerary between 2 markers which are defined in this geoJSON file:
{
"type": "FeatureCollection",
"features":
[
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-73.563032, 45.495403]},
"properties": {"prop0": "value0"}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-73.549762, 45.559673]},
"properties": {"prop0": "value0"}
}
]
}
The two markers are displayed well on the map.
Now I want to create an itinerary (car), between those two points.
I have this javascript function, which allows me to draw an itinerary from a form filled by the user:
function calculate() {
origin = document.getElementById('origin').value;
destination = document.getElementById('destination').value;
var request = {
origin: origin,
destination: destination,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
And now, I would like to replace the "origin" and "destination", by the 2 points defined in my geoJSON file, in order to create an itinerary between those two points.
Any idea ?
Thank you for your help !
One possible solution, use the Google Maps Data Layer to display your GeoJSON. The use it to retrieve the coordinates and get directions between them. The below code assumes 2 points (and uses your example with 2 points):
working fiddle