I want the GPS Coordinates of a DJI Drone in iOS. I need the method or property to get GPS location when Takeoff.
You basically have two options:
1/ Delegation on DJIFlightController aka DJIFlightControllerDelegate Protocol
You will implement this method and get a DJIFlightControllerState object which will have a location:
- (void)flightController:(DJIFlightController *_Nonnull)fc didUpdateState:(DJIFlightControllerState *_Nonnull)state {
CLLocation *myCurrentLocation = state.aircraftLocation;
// Do something here.
}
2/ Using the keyed interface and this key DJIFlightControllerParamAircraftLocation (see SDK Key note) This key will send you a value which contains a CLLocation.
Then you could either do a simple get
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
}
or listen to all updates
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
}
}
Just don't forget to stop listening when you're done.
I hope this helps.
PS: I've mixed Swift and Obj-C because you can use either.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.