Python WinRT 地理定位运行时错误

发布于 2025-01-12 10:55:27 字数 1321 浏览 0 评论 0原文

我正在尝试使用 WinRT API 以及这篇文章中建议的解决方案从我的 Windows 设备读取地理坐标:

import winrt.windows.devices.geolocation as wdg, asyncio

async def getCoords():
    locator = wdg.Geolocator()
    pos = await locator.get_geoposition_async()
    print(pos)
    return [pos.coordinate.latitude, pos.coordinate.longitude]
    
asyncio.run(getCoords())

不幸的是,我遇到以下错误...没什么可继续的:

Traceback (most recent call last):
  File "C:\path\to\locator.py", line 9, in <module>
    asyncio.run(getCoords())
  File "C:\path\to\anaconda3\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\path\to\anaconda3\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\path\to\locator.py", line 5, in getCoords
    pos = await locator.get_geoposition_async()
RuntimeError

我也尝试了 WinRT 文档 运气不佳。

大约一年前,这个解决方案对我有用。我已从 Windows 10 切换到 Windows 11。这是否可能是 Windows 11 问题?

I am trying to read the geocoordinates from my windows device using the WinRT API with the solution suggested in this post:

import winrt.windows.devices.geolocation as wdg, asyncio

async def getCoords():
    locator = wdg.Geolocator()
    pos = await locator.get_geoposition_async()
    print(pos)
    return [pos.coordinate.latitude, pos.coordinate.longitude]
    
asyncio.run(getCoords())

Unfortunately, I run into the following error...not much to go on:

Traceback (most recent call last):
  File "C:\path\to\locator.py", line 9, in <module>
    asyncio.run(getCoords())
  File "C:\path\to\anaconda3\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\path\to\anaconda3\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\path\to\locator.py", line 5, in getCoords
    pos = await locator.get_geoposition_async()
RuntimeError

I've also tried the exact solution in the WinRT Documentation without much luck.

This solution worked for me about a year ago. I have since switched from Windows 10 to Windows 11. Is it possible this is a Windows 11 issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2025-01-19 10:55:27

winrt 不再维护,您可以使用社区支持的 winsdk 分支。

winrt is no longer maintained, you can use the community-supported winsdk fork.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文