I have a weird problem trying to combine a somewhat dynamic Google Maps display. I have overlays on the map that I would call a function when clicked. At first I had everything hardcoded, so I had a function for each overlay, for example:
google.maps.event.addListener(southEast, 'click', showSouth); function showSouth() {
This worked without problems, but then I made the whole page more dynamic, so I decided to make one function that will pass an identifier, and then display based on this, which, in my opinion, should have been configured initially anyway, I changed code to look more like this:
google.maps.event.addListener(southEast, 'click', showArea(1)); function showArea(id) {
The function worked, but the problem is that it is invoked when the page loads. After studying, I found out that when you call a function with parentheses, this function is called immediately and then refers to the return value. a source
So, now I'm a little fixated on how to pass this identifier to a function without calling the function immediately. I found some hacker ways to do this that might work, but I feel that this should not be something that I have to crack together ...
Matt McClure
source share