There was an add-on (MapView) that displays a map in a project that manages Kivy add-ons called Kivy Garden, so I tried it.
Details of Garden are below
https://kivy.org/docs/api-kivy.garden.html
You can install it with pip.
pip install kivy-garden
For the time being, read the README on Github and prepare.
https://github.com/kivy-garden/garden.mapview
First, install the required environment.
pip install futures requests
Next, install mapview.
garden install mapview
Now you are ready to go.
For the time being, I will display a map centered on Tokyo Station.
main.py
from kivy.garden.mapview import MapView
from kivy.app import App
class MapViewApp(App):
def build(self):
mapview = MapView(zoom=15, lat=35.681382, lon=139.766084)
return mapview
MapViewApp().run()
The execution result is as follows. A map centered on Tokyo Station was displayed.
Next, try displaying a marker at the location of Tokyo Station. Rewrite the code as follows.
main.py
from kivy.garden.mapview import MapView, MapMarkerPopup
from kivy.app import App
class MapViewApp(App):
def build(self):
mapview = MapView(zoom=15, lat=35.681382, lon=139.766084)
marker1 = MapMarkerPopup(lat=35.681382, lon=139.766084)
mapview.add_marker(marker1)
return mapview
MapViewApp().run()
When I looked at the execution result, the marker was displayed well.
So it was very easy to display the map. By the way, the map called in MapView is that of OpenStreetMap. (http://www.openstreetmap.org/)
Recommended Posts