- Never use addOverlay before you call setCenter. If you do, you will experience the "Cannot call 'getProjection' on null" error which results from Google Maps trying to place a marker on a map that does not exist.
- Attach to events in a separate function. In one of the map API examples I found the nice functionality to pop a message box when the user clicks on a marker. This is done through the GEvent.addListener call. The problem comes when addListener and addOverlay are called within the same function. This causes Google Maps to always display the same pop-up at the same location regardless of which marker has been clicked.
More tips and tricks to come at a later point. :)
2 comments:
Heya--
Interesting project (gt).
Re 2 - That's a general issue in JS called function closure. We have documentation on that here:
http://code.google.com/apis/maps/documentation/events.html#Event_Closures
It's a common issue in JS when attaching listeners in a loop... but I also ran into it first when using the Maps API.
interesting... thanks for the comment!
I've also found this additional info on Javascript closures:
http://www.jibbering.com/faq/faq_notes/closures.html
Post a Comment