I'm a beginner with the Google Maps API, and wrote this JavaScript code to show a simple road map to the end user:
var originLatLng = new google.maps.LatLng(OrginLat, OrginLng);
var destinationLatLng = new google.maps.LatLng(DestLat, DestLng);
directionsService.route({
origin: originLatLng,
destination: destinationLatLng,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function (response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}//end of function
Now I want to enable click events on the road. For example when a user clicks on the road, show an alert. How can I write that code? Thanks all.