Kivy is used for making cross platform application in python and geopy is used for geocoding webservices address, distance ,coordinates latitude, longitude from address. By below code we can use it with kivy to display location address.

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from geopy.geocoders import Nominatim
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.properties import StringProperty
kv = '''
BoxLayout:
orientation: 'vertical'
Label:
id:newloc
text: 'location'
Button:
text:'2nd press me'
on_press:root.ids.newloc.text=app.myloc
Button:
text:'press me'
on_press:app.loc()
'''      
class MyApp(App):
myloc=StringProperty()
def build(self):
return Builder.load_string(kv)
def loc(self):
m_lat = 24
m_lon = 76
geolocator = Nominatim(user_agent="XY")
location = geolocator.reverse('{},{}'.format(m_lat,m_lon))
self.myloc=location.address
return print(location.address)
if __name__ == '__main__':
MyApp().run()

By SC

Leave a Reply

Your email address will not be published. Required fields are marked *