DJI-Mobile-SDK-Tutorials / Android-GSDemo-GoogleMap

A Demo for using DJI Mobile SDK to create a Waypoint Mission App using Google Map.
MIT License
28 stars 55 forks source link

How to get gps location of Spark? #21

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi, I am trying to use this tutorial to make Spark's gps location but not able to access it, even flgihtcontroller class. how to get flightcontroller class from Spark?

dji-dev commented 4 years ago

Agent comment from William Wong in Zendesk ticket #36667:

Dear Client Thank you for contacting DJI.

please refer to the code below. XXXApplication.getProductInstance().getFlightController.getState().getAircraftLocation.

Hopefully our solution can help you. Kindly Regards, DJI Developer Support

ghost commented 4 years ago

Thank you for your reply, Mr Wong! I have one more questions to ask!

What is the class "Flightcontollerkey" for? There are some flight controller key of aircraft location. Should we use that key for obtaining location info from flight controller?

dji-dev commented 4 years ago

Agent comment from William Wong in Zendesk ticket #36667:

Dear Client Thank you for contacting DJI.

You don't need to worry about the key for now. It is another way to access the data such as aircraft location. The tutorials do not describe clearly how to use them. So in this stage I would suggest you just simply use the getter and setter functions.

Hopefully our solution can help you. Kindly Regards, DJI Developer Support

ghost commented 4 years ago
private void initFlightController() {

    BaseProduct product = DJIDemoApplication.getProductInstance();
    if (product != null && product.isConnected()) {
        if (product instanceof Aircraft) {
            mFlightController = ((Aircraft) product).getFlightController();
            Log.d(TAG, "mFlightController :"+mFlightController);
            Log.d(TAG, "getAircraftlocaiton :"+mFlightController.getState().getAircraftLocation());

        }
    }

    if (mFlightController != null) {
        mFlightController.setStateCallback(new FlightControllerState.Callback() {

            @Override
            public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
                droneLocationLat = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
                droneLocationLng = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
                Log.d(TAG, "droneLocationLat :"+droneLocationLat+",\""+"droneLocationLng :"+droneLocationLng);
                updateDroneLocation();
            }
        });
    }
}

This is the original code that I added some logs. What should it be changed for Spark ?

dji-dev commented 4 years ago

Agent comment from William Wong in Zendesk ticket #36667:

Dear Client Thank you for contacting DJI.

You don't need to change it. By the way, what do you mean by cannot access it. What is the error return? You have to make sure the drone has good GPS signal to receive the data.

Hopefully our solution can help you. Kindly Regards, DJI Developer Support

ghost commented 4 years ago

I mean, when I make a log of aircraft location, it returns always null. But I think the problem is that I am testing it in a building. Thank you for your reply! I will use the dji assistant 2 simulation program