简体   繁体   English

更新PointAnnotation位置 android java

[英]Update PointAnnotation location android java

I'm trying to show the location of a DJI Drone on the Mapbox map and constantly update it's location.我试图在 Mapbox map 上显示 DJI 无人机的位置并不断更新它的位置。 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.我在 map 加载时创建无人机注释,每次无人机从回调中给我一个新位置时,我都会更新它的位置。 But my problem is, sometimes when I'm moving the map it gives me an error但我的问题是,有时当我移动 map 时,它会给我一个错误

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.我意识到这个错误是由 UpdateDroneMarker 引起的(可能是因为相机动画),所以我试图找到一种不同的方法来更新无人机的位置。 Hope someone could help me, thank you.希望有人能帮助我,谢谢。

Try running on ui thread.尝试在 ui 线程上运行。 I don't know for specific for mapbox, however callbacks from dji are not running on ui thread, so I would try that first.我不知道 mapbox 的具体情况,但是来自 dji 的回调没有在 ui 线程上运行,所以我会先尝试一下。 Otherwise you will get all kinds of strange errors.否则你会得到各种奇怪的错误。

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

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