-1

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.

almcd
  • 1,069
  • 2
  • 16
  • 29
behzad razzaqi
  • 275
  • 2
  • 8
  • 23

1 Answers1

-1

Try this:

google.maps.event.addListener(map,'click',function(){
    if(map.mapTypeId == "roadmap"){
        alert('ok')
    }
})
jkdev
  • 11,360
  • 15
  • 54
  • 77
Akshay
  • 815
  • 7
  • 16