【发布时间】: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