Google Maps API setImage or no more events redefinition

Before Google Maps API in version 2.75 changing icon for GMarker was not so easy. Why? Deleting old marker and creating new one is quite straightforward. But deleting marker means delete events associated with this particular marker. And recreating them for new one makes things much more complicated. Especially when events are added during application life time, You have to watch which were added and what listeners are responsible for handling them. Or I should write You had, since setImage() does just that – replaces image associated with marker. Deleting is no more required.

As You may expect I’m preparing an update to RNS. With this development round I’m also bringing application to compatibility with current stable Rails (from 1.1.6 to 1.2.3). And I have discovered change with behavior, in Ajax.Updater in parameters option. In Rails 1.1.6 it can be sign symbol used several times in string (like swlat=333.3;swlng=444.4) in 1.2.3 string is truncated on second sign symbol. I have rewritten my code to encode string in other format in only one parameter and Rails application unpacks it before processing. Other solution could be to play with postBody Ajax.Updater property. This allow to set whole body of request, so we can set many variables.

Now go back to coding, some few more features wait to be implemented!

Join the Conversation


  1. I change the icons of selected markers to RED when they are selected and change them back when user clicks an “unselect” button. THis works just fine, even for panning the map. BUT, whenever the zoom is used, the original marker color is returned!!! I have tried .setImage, and removeOverlay/addOverlay, but still they change back after zoom.
    I even added a listenevent for “zoomend” to redraw them, BUT STILL IT DOESN”T WORK. Any ideas???
    I am desparate.


  2. It is hard to say why it does not work without code. Could You provide a link to map?

    If it is not possible – are You sure that listener event for zoomend gets executed? If not, make sure (use GLog or alert to check this).

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.