【问题标题】:Using CoreLocation from python on OS X在 OS X 上使用 python 的 CoreLocation
【发布时间】:2015-05-11 18:57:04
【问题描述】:

我想使用 Python 中的 CoreLocation API 获取我的 Mac 的当前位置。我知道我可以让他们调用一些命令行可执行文件或类似的东西,但我有兴趣使用 CoreLocation 自己的 Python 绑定。

到目前为止,我可以创建一个应充当委托的类并创建CLLocationManager 的实例。调用 startUpdatingLocation() 会显示 OS X 的位置权限请求者,并且位置图标会出现在菜单栏上,但我从未调用过任何委托方法。 authorizationStatus() 返回3,即kCLAuthorizationStatusAuthorized

怎么了?

"""
Core Location Python test
"""

import Cocoa
import CoreLocation

locaitonSearchFinished = False

class CLTestDelegate(Cocoa.NSObject):
    def locationManager_didUpdateLocations_(self, manager, locations):
        print u"New Location: %s" % locations
        locaitonSearchFinished = True

    def locationManager_didFailWithError_(self, manager, error):
        print u"Error updating location: %s" % error
        locaitonSearchFinished = True

    def locationManager_didChangeAuthorizationStatus_(self, manager, status):
        print u"Status: %s" % status

delegate = CLTestDelegate.alloc().init()
locationManager = CoreLocation.CLLocationManager.alloc().init()
locationManager.setDelegate_(delegate)
locationManager.startUpdatingLocation()

print locationManager
print delegate
print CoreLocation.CLLocationManager.authorizationStatus()

while locaitonSearchFinished == False:
    pass

【问题讨论】:

    标签: python macos core-location cllocationmanager


    【解决方案1】:

    我刚刚添加了打印语句 打印 locationManager.location() 到您的代码以获取结果。

    CoreLocation AttributeError的帮助下

    【讨论】:

      猜你喜欢
      • 2014-10-15
      • 2013-06-03
      • 2015-12-24
      • 1970-01-01
      • 2011-05-30
      • 2017-02-17
      • 2012-11-07
      • 1970-01-01
      • 2010-11-30
      相关资源
      最近更新 更多