def get_current_location2():
'''Gets the current location from geolocation via IP (only method
currently supported)
'''
latitude = 0
longitude = 0
bus = dbus.SessionBus()
# For now we default to the UbuntuGeoIP provider and we fall back to
# Hostip. We should probably be cleverer about provider detection, but
# this solution works for now and does not rely solely on UbuntuGeoIP,
# which means qreator can run on other distros
try:
geoclue = bus.get_object(
'org.freedesktop.Geoclue.Providers.UbuntuGeoIP',
'/org/freedesktop/Geoclue/Providers/UbuntuGeoIP')
position_info = geoclue.GetPosition(
dbus_interface='org.freedesktop.Geoclue.Position')
latitude = convert(position_info[2])
longitude = convert(position_info[3])
except dbus.exceptions.DBusException as e:
print('Error 1', e)
try:
geoclue = bus.get_object(
'org.freedesktop.Geoclue.Providers.Hostip',
'/org/freedesktop/Geoclue/Providers/Hostip')
position_info = geoclue.GetPosition(
dbus_interface='org.freedesktop.Geoclue.Position')
latitude = convert(position_info[2])
longitude = convert(position_info[3])
except dbus.exceptions.DBusException as e:
print('Error 2', e)
return latitude, longitude
评论列表
文章目录