I’m not able to open an infoWindow when I select a polygon. Here’s my code:
// Create Polygon
var polyline = new google.maps.Polygon({path:path, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2, clickable:false});
// Place Polygon on Map
polyline.setMap(map);
map.setCenter(new google.maps.LatLng(35.910200,-84.085100));
// Create InfoWindow object
var infowindow = new google.maps.InfoWindow({
content: ' ',
suppressMapPan:true
});
// Create Click Event for Polygon
eventPolygonClick = google.maps.event.addListener(polyline, 'click', function() {
// Load Content
infowindow.setContent("CLICKED me");
// Open Window
infowindow.open(map, polyline);
});
I would like to also pass the polygon and its respective content as variables to the eventPolygonClick. Is this possible?
Try this, use the latlng received from the click event to create a marker, and use that as the second parameter in the infowindow.open call.