首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Python中获取Geoclue地理位置?-什么是桌面id参数?

如何在Python中获取Geoclue地理位置?-什么是桌面id参数?
EN

Stack Overflow用户
提问于 2020-01-10 15:33:28
回答 1查看 519关注 0票数 3

我正在尝试使用GeoClue for Linux和Python接口(gir1.2-geoclue-2.0包)获取位置(经度/经度)。documentation for c几乎与这里的api函数匹配,但是我不确定我应该发送什么“桌面id”……应用程序所请求的任何有效.desktop文件??完整路径或唯一名称??

代码语言:javascript
复制
>>> 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)

最后一个命令挂起,不返回任何内容。在获取笔记本电脑/设备的大致位置时,我是否错过了一个步骤?据我所知,它应该能够以类似于whatsmyip.com的方式从网络中读取设备的位置?

更新:我能够通过与返回值交互获得大致位置,

代码语言:javascript
复制
c = Geoclue.Simple.new_sync('something',Geoclue.AccuracyLevel.NEIGHBORHOOD,None)

但是第一个参数应该是什么呢?什么是“桌面id"??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-24 04:27:36

虽然我不确定这个参数应该是什么,但我已经在Python中实现了它。完整的解释可以在here上找到。

代码语言:javascript
复制
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'))
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59677218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档