google.maps.event.addListener(map, 'click', function( event ){
alert( "Latitude: "+event.latLng.lat()+" "+", longitude:"+event.latLng.lng() );
});
this code gives us lat long when we click on google map. but it does not work when there is our own geojson layer that is if we have our own geojson layer of polygon over google map then clicking inside that polygon the above code would not work
Either add your click event listener to the Data layer or set the Data layer to not accept mouse events (clickable:false
).
Set event listener on Data layer:
google.maps.event.addListener(map, 'click', function(event) {
alert("Latitude: " + event.latLng.lat() + " " + ", longitude: " + event.latLng.lng());
});
// Set mouseover event for each feature.
map.data.addListener('click', function(event) {
alert("Latitude: " + event.latLng.lat() + " " + ", longitude: " + event.latLng.lng());
});
Set Data layer to clickable: false
:
map.data.setStyle(function(feature) {
var color = 'gray';
var opacity = 0.45;
return /** @type {google.maps.Data.StyleOptions} */ ({
fillColor: color,
strokeColor: "black",
strokeWeight: 2,
strokeOpacity: opacity,
fillOpacity: opacity,
clickable: false
});
});