Open zijian98 opened 3 years ago
Yes you can with the state of the flight controller for example :
drone.getFlightController().getState().getAircraftLocation()
It returns a LocationCoordinate3D which contains the latitude, longitude and altitude.
You can also set a callback on the state of the flight controller to get all updates of the position with setStateCallback
Yes you can with the state of the flight controller for example :
drone.getFlightController().getState().getAircraftLocation()
It returns a LocationCoordinate3D which contains the latitude, longitude and altitude. You can also set a callback on the state of the flight controller to get all updates of the position with setStateCallback
Hi, I've tried it but the coordinates remained at 0 and satellite count will not update unless I re enter the page again. Do you have any example that I can reference to? I'm not sure if I am missing anything.
This is my code: `//Register BroadcastReceiver in onCreate method
IntentFilter filter = new IntentFilter();
filter.addAction(FlyDJI.FLAG_CONNECTION_CHANGE);
registerReceiver(mReceiver, filter);
getData();
}
public BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mData.setText("Latitude: " + mAircraftLat + "\nLongitude: " + mAircraftLong + "\nAltitude: " + mAircraftAlt + " m");
mGPS.setText("No. of Satellite: " + mGPSCount);
mSignal.setText(mLevel.toString());
}
};
private void getData() {
FlightController mFlightController = FlyDJI.getAircraftInstance().getFlightController();
mFlightController.setStateCallback(new FlightControllerState.Callback() {
@Override
public void onUpdate(FlightControllerState state) {
mAircraftLat = state.getAircraftLocation().getLatitude();
mAircraftLong = state.getAircraftLocation().getLongitude();
mAircraftAlt = state.getAircraftLocation().getAltitude();
mGPSCount = state.getSatelliteCount();
mLevel = state.getGPSSignalLevel();
}
});
}`
Thanks
Are you testing your app inhouse? There is no GPS signal inhouse. Try connect with Assistant 2 simulator and fake a GPS signal, then everything works.
Are you testing your app inhouse? There is no GPS signal inhouse. Try connect with Assistant 2 simulator and fake a GPS signal, then everything works.
Yes. I've tried it but the GPS coordinates only updates in the simulator but not on my app. Is it supposed to update based on the simulator's coordinates?
Then I suspect your issue will be the UI update. You have mentioned the value update when you enter the page. It seems like you are setting your UI refresh in a onCreate function which means your UI didn't refresh properly. Feel free to try our Sample, you can run a waypointMission to check those value changes.
Then I suspect your issue will be the UI update. You have mentioned the value update when you enter the page. It seems like you are setting your UI refresh in a onCreate function which means your UI didn't refresh properly. Feel free to try our Sample, you can run a waypointMission to check those value changes.
I am using this sample for reference: https://developer.dji.com/mobile-sdk/documentation/android-tutorials/GSDemo-Google-Map.html
Everything is working but I could not get the marker on the map to follow the drone in my app. The only modification I did was removing the fixed GPS coordinates from the code. Is there a way for the app to auto detect the drone location based on the simulator?
This is the code I've used to get the coordinates:
`private void initFlightController() {
BaseProduct product = FlyDJI.getProductInstance();
if (product != null && product.isConnected()) {
if (product instanceof Aircraft) {
mFlightController = ((Aircraft) product).getFlightController();
}
}
if (mFlightController != null) {
mFlightController.setStateCallback(new FlightControllerState.Callback() {
@Override
public void onUpdate(FlightControllerState djiFlightControllerCurrentState) {
droneLocationLat = djiFlightControllerCurrentState.getAircraftLocation().getLatitude();
droneLocationLng = djiFlightControllerCurrentState.getAircraftLocation().getLongitude();
stringLAT.append("Latitude: ").append(droneLocationLat);
stringLNG.append("Longitude: ").append(droneLocationLng);
stringMODE.append("Flight mode: ").append(djiFlightControllerCurrentState.getFlightMode().name());
updateDroneLocation();
mLat.setText("Latitude: " + stringLAT);
mLong.setText("Longitude: " + stringLNG);
mMode.setText("Flight mode: " + stringMODE);
}
});
}
}`
`private void updateDroneLocation() {
LatLng pos = new LatLng(droneLocationLat, droneLocationLng);
//Create MarkerOptions object
final MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(pos);
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.aircraft));
runOnUiThread(new Runnable() {
@Override
public void run() {
if (droneMarker != null) {
droneMarker.remove();
}
if (checkGpsCoordination(droneLocationLat, droneLocationLng)) {
droneMarker = gMap.addMarker(markerOptions);
}
}
});
}`
Thanks
I like to know how do I get the UA bearing? Similar to [Android Location getBearing](https://developer.android.com/reference/android/location/Location#getBearing()).
I am using SDK V5.10.0 in that SDK all functions and classes are not available which you have provided in this answer then how do I get the drone's current Location, and other information like Pitch, Roll, YAW, vertical throttle, etc once my drone is connected.
Can you please help me with this?
Thanks.
HI, I'm trying to get the gps coordinates value. Is there a way which the drone can retrieve the longitude and latitude values in real time and display it on my app using the SDK?