If you’ve had much to do with Google Maps, then you’ve probably come across the GMarker object. You use it when making your own custom markers on a Google Map.

You typically use it like this:

  
var stdIcon.image = "/images/myMarker.png";  
stdIcon.iconSize = new GSize(20, 20);  
stdIcon.iconAnchor = new GPoint(16, 16);  
stdIcon.infoWindowAnchor = new GPoint(25, 7);  
var  marker = new GMarker(point, {icon:stdIcon});  
map.addOverlay(marker);  

Once the marker’s been created and placed on the map, then there didn’t seem to be anyway to get the image element of the marker so I could do some funky stuff with it.

So, I opened up FireBug and had a look at the GMarkers internals:

The property I had been looking for was cleverly obfuscated with the boring name of Mj. “Aha!” I thought, “Gotcha Google! Can’t hide it away from me!” and proceeded to write code that referenced this highly secretive Mj property.

A month went by though, and I noticed that my code no longer worked – the Mj property had been renamed to Zj, breaking all my code! Teach me for referencing an Obfuscated property I guess.

So, I got around it using Javascript reflection.

  
function getMarkerImage(marker) {  
  for (var memberName in marker) {
    var memberObj = marker[memberName];
    if ((memberObj) && (memberObj.tagName  "IMG") {
      return memberObj;            
    }
  }
}

This method finds the first property of the GMarker class that has a tagName “IMG”.

Need to find a lawyer for your business? Get in touch with my company Lexoo and we'll find you a great one for free.