I'm using Google Maps API v3 and need to offset markers based on the current zoom level.
I have a global variable current_zoom_level, and an event listener for zoom in/out:
google.maps.event.addListener(map, 'zoom_changed', function() { current_zoom_level = map.getZoom(); alert(current_zoom_level); });
I've tried this bit in the initialization code and the code that calculates the offset. The alert displays the correct current zoom level, but when I access it in build_loan_markers() (where I calculate offsets) current_zoom_level is undefined.
function build_loan_markers ()
{
var offset;
alert(current_zoom_level);
if(!window.current_zoom_level){
window.current_zoom_level = 1;
}
offset = 1/(window.current_zoom_level^2);
alert('zoom: ' + current_zoom_level + ' offset: ' + offset);
etc..
}
How can I globally set this variable?
Thank you!