I did define the global variable by var in the global scope. We needed to offset the markers because four markers on top of each other (representing different things) would be useless.
The reason the global var didn't look like it was getting set was because the function that needed it was only ever called once, not each time the page was zoomed in/out on. Thank you! On Dec 12, 10:26 am, kodemonki <[email protected]> wrote: > 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! -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
