[Python] Folium get location and zoom level

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to find the current view location of a folium map, and the current zoom level.

    I created a map object

    >> self.map1 = folium.Map(
    tiles='Stamen Terrain',
    zoom_start=zoom0,
    location=coordinate
    )



    After a user interacted with it, I'd like to know the current viewed coordinate & zoom level. (in this case to save and recall at the next startup)

    >> print(self.map1.getLocation())
    >> print(self.map1.getZoom())


    yielding

    AttributeError: 'Map' object has no attribute 'getLocation'
    AttributeError: 'Map' object has no attribute 'getZoom'


    I believe folium uses leaflet, which has a getZoom() method itself according to: https://leafletjs.com/reference.html#Map

    How can one access these parameters in folium/python?

    Continue reading...

Compartilhe esta Página