Hi I have a google maps polygons array named regionPolygons. Now I want each time I click a polygon, my map will set its center at that of the polygon.
Here is how I implement it.
for (i = 0; i < regionPolygons.length; i++) {
google.maps.event.addListener(regionPolygons[i], 'click', function () {
// do the stuff, things seem ok here
}
}
Now whichever polygons I click, I am taken to the center of the last polygon. How can I let Google maps now which polygon is clicked? Thank you
Edit: My question a duplicate. It seems that copying the same code to the new function work. It seems that Javascript create new copy of the variable when it is passed from the main program to a sub program. Could any one help me explain about it?