Getting Googlemap existing zoom level

Title says it all. I’m trying to figure out how to query the map to get the current zoom level so that I can reset it to that level after a user action. Is this possible?

Have you tried this event?
zoom_changed - when the map zoom property changes.
something like:
self.map.set_event_handler(‘zoom_changed’, register_zoom_level_function)

Then you need to write the register_zoom_level_function which would get what you need from the raised event

Trapping the event isn’t really the issue. I can get that from the bounds_changed event already. The issue is getting the current zoom level of the map.

I think what I need is this:
https://developers.google.com/maps/documentation/javascript/reference/map#Map.getZoom

Hi @shopinthewoods, I’m afraid this isn’t currently possible using our wrapping of the Google Maps API, however you can use the underlying Google Maps Javascript API as described in this post:

1 Like

Hi @shopinthewoods, we’ve fixed the GoogleMap component so that zoom is the current zoom level, so this is now possible.

Here’s an app that demonstrates it - click the button to get the zoom level:

  def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    self.label_1.text = self.map_1.zoom

https://anvil.works/build#clone:2LFJTROJZVAASUJV=RTW2NGJXGIQBWKN44UBN2SFC

1 Like