Black Lives Matter. Please consider donating to Black Girls Code today.

Get Lat long from Maps on mouse click, python dash

I want to get the lat lon values from map anywhere when i click.
I can only get the Data point lat lon values using clickData.
Is there any way to capture or store lat lon values by clicking anywhere on the maps??


Hey @rishabhjain,

Maybe you can try to attach the output of a callback to the children of an empty div.

and display the coordinates with :

 str(figure['layout'].update(dict(mapbox = dict(center = dict (lat = relayoutData['']['lat'], lon = relayoutData['']['lon'] ), zoom = relayoutData["mapbox.zoom"]))))

I know I was able to get the coordinates of my mouse when I was hovering the map with this formula. The aim was to avoid to zoom in/out everytime I was hovering on a new data point

Any news did you find a solution
i am facing the same problem and i can’t find one

Hi, you can use visdcc.Run_js to write your own javascript event listener and capture the values. :slightly_smiling_face:
here is the example code

do you have any example about using Visdcc with scattermapbox ?

In Dash Leaflet, you can get the mouse click events (which contains lat, lon information). See e.g. example 1 here,

1 Like