Is it possible to return the lat and long from a mouse click over a map in folium, I have tested via latlong popover method and can see the events added as children to the map, however unable to find the actual lat long values within each child object.
You've got two objects for this:
features.ClickForMarker
features.LatLngPopup
I hope one of these will help you. Otherwise, can you give more precisions on the behavior you expect, please ?
okay, i have the following:
map_3 = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',
zoom_start=13)
folium.LatLngPopup().add_to(map_3)
How do i get the actual lat and long values from the children once i have clicked on the map. I am trying to use them to start another process in notebook.
Tks
How do i get the actual lat and long values from the children once i have clicked on the map. I am trying to use them to start another process in notebook.
There is no way to get the position values back as python objects right now but that would be an awesome addition :wink:
Yeah, if there's such addition that would be awesome. I really need that functionality.
Yeah, if there's such addition that would be awesome. I really need that functionality.
Check ipyleaft or the EarthSim project for js-python interactions. Folium is Python -> JS only.
Thank you ocefpaf, didn't expect your reply so quickly. So I checked these two libraries, could not find what I want. What I really want is to showing an OSM tile, with the function to let user add a marker using mouse. Then maybe there's a confirm mechanism to ask user to confirm the marker's location. After confirm, my map will store the marker's lat n long values to a database. Do you think this is too much for a simple visualization tool? Maybe I'll stick to Geodjango? Thanks
yangkey87, do you have a solution to what you're trying to do? I'm looking to do something similar and have not been able to figure out how to store the user-clicked lat/lon data. Thanks.
I've ended up by saving the map to an html file on disk and editing javascript part there. This way I'm able to get corrdinates using e.latlng inside function latLngPop(e) {...}.
However it restricts you to work with that coordinates in the map.html, not in initial python script.
Thank you ocefpaf, didn't expect your reply so quickly. So I checked these two libraries, could not find what I want. What I really want is to showing an OSM tile, with the function to let user add a marker using mouse. Then maybe there's a confirm mechanism to ask user to confirm the marker's location. After confirm, my map will store the marker's lat n long values to a database. Do you think this is too much for a simple visualization tool? Maybe I'll stick to Geodjango? Thanks
I'm finding the same thing, anyone know how to do it?
folium really is not build for this kind of stuff. It's a one way street from Python to html/JS.
One way of solving this I can think of is making a webapp. You'll have to do some web dev kind of work yourself. Something like a Flask webapp showing maps. Add custom Javascript that sends the coordinates to a URL of your Flask webapp. That way you have the coordinates in Python and can store them in a db or whatever it is you want.
Here's an example to get started with folium and Flask: https://python-visualization.github.io/folium/flask.html After that you're on your own I'm afraid. Though if you make a small demo we would gladly host it in our example gallery.
folium really is not build for this kind of stuff. It's a one way street from Python to html/JS.
One way of solving this I can think of is making a webapp. You'll have to do some web dev kind of work yourself. Something like a Flask webapp showing maps. Add custom Javascript that sends the coordinates to a URL of your Flask webapp. That way you have the coordinates in Python and can store them in a db or whatever it is you want.
Here's an example to get started with folium and Flask: https://python-visualization.github.io/folium/flask.html After that you're on your own I'm afraid. Though if you make a small demo we would gladly host it in our example gallery.
Okay I'll let you know if it works馃槃
I am stuck with the same issue! Is there any update on this thread?
thanks :)
In my case I use folium plugin "Draw" for set markers and framework PyQt5. Everything work fine.
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
from folium.plugins import Draw
import folium, io, sys, json
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
m = folium.Map(location=[55.8527, 37.5689], zoom_start=13)
draw = Draw(
draw_options={
'polyline':False,
'rectangle':True,
'polygon':True,
'circle':False,
'marker':True,
'circlemarker':False},
edit_options={'edit':False})
m.add_child(draw)
data = io.BytesIO()
m.save(data, close_file=False)
class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
def javaScriptConsoleMessage(self, level, msg, line, sourceID):
coords_dict = json.loads(msg)
coords = coords_dict['geometry']['coordinates'][0]
print(coords)
view = QtWebEngineWidgets.QWebEngineView()
page = WebEnginePage(view)
view.setPage(page)
view.setHtml(data.getvalue().decode())
view.show()
sys.exit(app.exec_())
For disable alarm you need edit folium lib (../../foluim/plugins/draw,py)
remove line 63 -
alert(coords);
Most helpful comment
okay, i have the following:
How do i get the actual lat and long values from the children once i have clicked on the map. I am trying to use them to start another process in notebook.
Tks