我想使用Python的corelocationapi获取Mac的当前位置。我知道我可以让他们调用一些命令行可执行文件或类似的东西,但我对使用CoreLocation自己的Python绑定感兴趣。在
到目前为止,我可以创建一个类作为委托,并创建CLLocationManager
的实例。调用startUpdatingLocation()
显示了OSX的位置权限请求程序,位置图标出现在菜单栏上,但我从未调用过任何委托方法。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
我刚加了一份声明 打印位置管理器。位置() 以获取结果。在
借助于:CoreLocation AttributeError
相关问题 更多 >
编程相关推荐