6

I am looking for a way to get coordinates from a marker/popup in Folium. I want to use the coordinates for further calculations. I know, that Folium is more for visualizing data and maps than getting information back.

I found an interesting post where the coordinates were sent back via href (https://gis.stackexchange.com/a/353035/168662), but this does not work for me. I am displaying a folium map in a PyQt5 Window.

Here is a simple code to display the coordinates when clicking on a map with Jupyter Notebook:

import folium


m = folium.Map()
popup1 = folium.LatLngPopup()

m.add_child(popup1)
m

To get the coordinates, I want something like:

print("Latitude of Popup: ", popup1.getLat() ) 
2
  • I'm really interested in this as well, if someone has an answer...
    – Laurent
    Commented Dec 8, 2020 at 9:56
  • Could you find an answer for this that works?
    – Ress
    Commented Aug 15, 2022 at 15:11

1 Answer 1

3

Look at this site. I think this may interest you: https://github.com/python-visualization/folium/blob/master/examples/plugin-MousePosition.ipynb

import folium
from folium.plugins import MousePosition


m = folium.Map()

MousePosition().add_to(m)

m
m = folium.Map()

formatter = "function(num) {return L.Util.formatNum(num, 3) + ' º ';};"

MousePosition(
    position="topright",
    separator=" | ",
    empty_string="NaN",
    lng_first=True,
    num_digits=20,
    prefix="Coordinates:",
    lat_formatter=formatter,
    lng_formatter=formatter,
).add_to(m)

m
2
  • 2
    It only prints the coordinate on the map. The question however is how to export it outside of the map as a variable?
    – Ress
    Commented Aug 15, 2022 at 15:10
  • The code snippet was helpful Commented Jan 2, 2023 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.