I'm trying to show the location of a DJI Drone on the Mapbox map and constantly update it's location. This is what I'm doing.
private void addDroneMarker(double latitude, double longitude){
Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.aircraft_icon)).getBitmap();
AnnotationPlugin annotationAPI = AnnotationPluginImplKt.getAnnotations(mapView);
pointAnnotationManager = PointAnnotationManagerKt.createPointAnnotationManager(annotationAPI, new AnnotationConfig());
PointAnnotationOptions pointAnnotationOptions = new PointAnnotationOptions()
.withPoint(Point.fromLngLat(longitude, latitude))
.withIconImage(bitmap);
dronePoint = pointAnnotationManager.create(pointAnnotationOptions);
}
private void updateDroneMarker(double latitude, double longitude){
dronePoint.setPoint(Point.fromLngLat(longitude, latitude));
pointAnnotationManager.update(dronePoint);
}
private void initFlightController(){
BaseProduct product = FPVApplication.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();
updateDroneMarker(droneLocationLat, droneLocationLng);
}
});
}
}
I create the drone annotation when the map loads and everytime the drone gives me a new location from the callback I update its location. But my problem is, sometimes when I'm moving the map it gives me an error
Error while setting camera options : std::exception
This error could cause the application to crash with a Fatal Error
Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x787c881d0c in tid 17420 (RenderThread), pid 17347
And I realized that this error was caused by the UpdateDroneMarker (maybe because of the camera Animation), so I'm trying to find a different way to update the drones location. Hope someone could help me, thank you.