简体   繁体   English

哪个功能用于获取DJI Drone for iOS的GPS坐标的准确位置

[英]Which Function is used for Get the exact location of GPS Coordinates of DJI Drone for iOS

I want the GPS Coordinates of a DJI Drone in iOS. 我想要iOS中DJI无人机的GPS坐标。 I need the method or property to get GPS location when Takeoff. 起飞时,我需要获取GPS位置的方法或属性。

You basically have two options: 您基本上有两个选择:

1/ Delegation on DJIFlightController aka DJIFlightControllerDelegate Protocol 1 / DJIFlightController aka DJIFlightControllerDelegate协议的委托

You will implement this method and get a DJIFlightControllerState object which will have a location: 您将实现此方法,并获得一个DJIFlightControllerState对象,该对象将具有以下位置:

- (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. 2 /使用带键的界面和此键DJIFlightControllerParamAircraftLocation (请参见SDK键注释)此键将向您发送一个包含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. PS:我将Swift和Obj-C混合使用,因为您都可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM