如何在 Python 中获取 Geoclue 地理定位? - 什么是桌面 ID 参数?
How do I get Geoclue Geolocation in Python? - What is desktop id parameter?
我正在尝试使用 Linux 的 GeoClue 和 Python 接口(gir1.2-geoclue-2.0
包)获取位置 (lat/lon)。 documentation for c 几乎与此处的 api 函数匹配,但我不确定我应该发送什么“桌面 ID”...应用程序请求的任何有效 .desktop
文件?完整路径或唯一名称??
>>> 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)
最后一个命令挂起,没有 return 任何东西。我是否缺少获取 laptop/device 的大致位置的步骤?据我了解,这应该能够以类似于 whatsmyip.com?
的方式从网络读取设备的位置
更新:我能够通过与 return 值交互获得粗略位置,
c = Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)
但是第一个参数应该是什么?什么是“桌面 ID”??
虽然我不确定那个参数应该是什么,但我已经在 Python 中使用它了。完整的解释可用 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'))
我正在尝试使用 Linux 的 GeoClue 和 Python 接口(gir1.2-geoclue-2.0
包)获取位置 (lat/lon)。 documentation for c 几乎与此处的 api 函数匹配,但我不确定我应该发送什么“桌面 ID”...应用程序请求的任何有效 .desktop
文件?完整路径或唯一名称??
>>> 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)
最后一个命令挂起,没有 return 任何东西。我是否缺少获取 laptop/device 的大致位置的步骤?据我了解,这应该能够以类似于 whatsmyip.com?
的方式从网络读取设备的位置更新:我能够通过与 return 值交互获得粗略位置,
c = Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)
但是第一个参数应该是什么?什么是“桌面 ID”??
虽然我不确定那个参数应该是什么,但我已经在 Python 中使用它了。完整的解释可用 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'))