Skip to content

Instantly share code, notes, and snippets.

@dlenski
Created December 18, 2019 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlenski/2dcb2b229138dc86c54776be11ef67d7 to your computer and use it in GitHub Desktop.
Save dlenski/2dcb2b229138dc86c54776be11ef67d7 to your computer and use it in GitHub Desktop.
Playing around with freedesktop/python-geoclue
#!/usr/bin/env python
# old, Python 2.x only :-(
# https://github.com/freedesktop/python-geoclue
from __future__ import print_function
import Geoclue
from datetime import datetime
print("Geoclue version %s" % Geoclue.VERSION)
dl = Geoclue.DiscoverLocation()
dl.init()
providers = dl.get_available_providers()
for provider in providers:
pname = provider['name']
print("\nTrying provider %s..." % pname)
if provider['position']:
dl.set_position_provider(pname)
position = dl.get_location_info()
print("\nGot position from %s\n%s" % (pname, "-"*len(pname)))
for k, v in position.items():
if k.endswith('_timestamp'):
v = datetime.fromtimestamp(v)
if isinstance(v, float):
v = '%.9g' % v
print("%-25s%s" % (k+':',v))
if provider['address'] and 'latitude' in position and 'longitude' in position:
dl.set_address_provider(pname)
address = dl.reverse_position(position['latitude'], position['longitude'], 1000)
if not address:
print("\nGot blank address from %s\n" % pname)
else:
print("\nGot address from %s\n%s" % (pname, "-"*len(pname)))
for k, v in address.items():
if k.endswith('_timestamp'):
v = datetime.fromtimestamp(v)
print("%-25s%s" % (k+':',v))
@maltegrosse
Copy link

as most of the examples are super outdated, so I wrote a golang dbus wrapper - quite handy to manage geoclue, https://github.com/maltegrosse/go-geoclue2 , see the /examples file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment