Black Lives Matter. Please consider donating to Campaign Zero's mission of ending police violence in America.
https://www.joincampaignzero.org

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??

2 Likes

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['mapbox.center']['lat'], lon = relayoutData['mapbox.center']['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 https://github.com/jimmybow/visdcc/blob/master/example/Run_js/Add_event_and_callback.py

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