[英]Which Function is used for Get the exact location of GPS Coordinates of DJI Drone for iOS
我想要iOS中DJI无人机的GPS坐标。 起飞时,我需要获取GPS位置的方法或属性。
您基本上有两个选择:
1 / DJIFlightController aka DJIFlightControllerDelegate协议的委托
您将实现此方法,并获得一个DJIFlightControllerState对象,该对象将具有以下位置:
- (void)flightController:(DJIFlightController *_Nonnull)fc didUpdateState:(DJIFlightControllerState *_Nonnull)state {
CLLocation *myCurrentLocation = state.aircraftLocation;
// Do something here.
}
2 /使用带键的界面和此键DJIFlightControllerParamAircraftLocation (请参见SDK键注释)此键将向您发送一个包含CLLocation的值。
然后,您可以做一个简单的获取
guard let locationKey = DJIFlightControllerKey(param: DJIFlightControllerParamAircraftLocation) else {
NSLog("Couldn't create the key")
return
}
guard let keyManager = DJISDKManager.keyManager() else {
print("Couldn't get the keyManager")
// This will happen if not registered
return
}
if let locationValue = keyManager.getValueFor(locationKey) {
let location = locationValue.value as! CLLocation
// do something
}
或听所有更新
guard let locationKey = DJIFlightControllerKey(param: DJIFlightControllerParamAircraftLocation) else {
NSLog("Couldn't create the key")
return
}
guard let keyManager = DJISDKManager.keyManager() else {
print("Couldn't get the keyManager")
// This will happen if not registered
return
}
keyManager.startListeningForChanges(on: locationKey, withListener: self) { (oldValue, newValue) in
if newValue != nil {
let location = newValue!.value as! CLLocation
// do something
}
}
只是别忘了在完成后停止收听。
我希望这有帮助。
PS:我将Swift和Obj-C混合使用,因为您都可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.