Wednesday, 20 February 2008

google maps marker z index

Google have now prevented access to marker.setZIndex() (which was undocumented method anyway) A work around to get your marker to the top is:

function add_marker(){
var marker = new GMarker(point,{zIndexProcess:importanceOrder});
marker.importance = 2; //higher importance = higher marker z index
the_map.addOverlay(marker);
}

function importanceOrder (marker,b) {
return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
}

which moves the marker higher up - note you'll need to do this after you've added all the markers to the map. Otherwise the next z-index will continue after the last one you added (effectively cancelling out your increase in z-index)