Search code examples
pythongeolocationgobject-introspectionfreedesktop.orggeoclue

How do I get Geoclue Geolocation in Python? - What is desktop id parameter?


I'm trying to get the location (lat/lon) using GeoClue for Linux, and the Python interface (gir1.2-geoclue-2.0 package). The documentation for c nearly matches the api functions here, but I'm not sure what "desktop id" I should send... any valid .desktop file that is what application is requesting?? A full path or unique name??

>>> Geoclue.Simple.new.__doc__
'new(desktop_id:str, accuracy_level:Geoclue.AccuracyLevel, cancellable:Gio.Cancellable=None, callback:Gio.AsyncReadyCallback=None, user_data=None)'
>>> Geoclue.Simple.new_sync('hi',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)

(process:7691): Geoclue-WARNING **: Error setting property 'DesktopId' on interface org.freedesktop.GeoClue2.Client: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface 'org.freedesktop.DBus.Properties' on object at path /org/freedesktop/GeoClue2/Client/2 (g-dbus-error-quark, 19)

(process:7691): Geoclue-WARNING **: Error setting property 'RequestedAccuracyLevel' on interface org.freedesktop.GeoClue2.Client: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface 'org.freedesktop.DBus.Properties' on object at path /org/freedesktop/GeoClue2/Client/2 (g-dbus-error-quark, 19)
__main__:1: Warning: g_object_unref: assertion 'object->ref_count > 0' failed
<Geoclue.Simple object at 0x7f4fde2ad8b8 (GClueSimple at 0x1b89340)>
>>> Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)

And the last command hangs, does not return anything. Am I missing a step in obtaining the general location of the laptop/device? From what I understand this should be able to read the location of the device from the network in similar manner to whatsmyip.com?

Update: I was able to get rough location by interacting with the return value,

c = Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)

but what is the first parameter supposed to be? What is a "Desktop id"??


Solution

  • Although I'm not sure what that one parameter should be, I have got it working in Python. A full explanation is available here.

    from gi.repository import Geoclue
    clue = Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)
    location = clue.get_location()
    print(location.get_property('latitude'), location.get_property('longitude'))