Created
December 18, 2019 01:32
-
-
Save dlenski/2dcb2b229138dc86c54776be11ef67d7 to your computer and use it in GitHub Desktop.
Playing around with freedesktop/python-geoclue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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