谷歌Map取消回调不会改变我的相机Angular 和位置我做错什么了?

nfeuvbwi  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(343)

我在onmapready()中添加了相机位置和动画回调。

CameraPosition cameraPosition =
               new CameraPosition.Builder()
                       .target(new LatLng(currentRoute.locations.get(1).getLatitude(),
                               currentRoute.locations.get(1).getLongitude()))
                       .tilt(60)
                       .bearing((float)currentRoute.getRouteEdges().getFirst().getHeading(currentRoute.getStart(), currentRoute.getFinish())-40)
                       .zoom(20)
                       .build();

       CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));

       turnByTurnMap.animateCamera(update, new GoogleMap.CancelableCallback() {
           @Override
           public void onFinish() {
               if(currentPosition<currentRoute.locations.size()-1){
                   float bearing = HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition).getLatitude(),
                           currentRoute.locations.get(currentPosition).getLongitude()).bearingTo(HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
  currentRoute.locations.get(currentPosition+1).getLongitude()));
                   CameraPosition cameraPosition =
                           new CameraPosition.Builder()
                                   .target(new LatLng(currentRoute.locations.get(currentPosition).getLatitude(),
                                           currentRoute.locations.get(currentPosition).getLongitude()))
                                   .tilt(60)
                                   .bearing(bearing)
                                   .zoom(20)
                                   .build();
                   currentPosition++;
               }
           }

           @Override
           public void onCancel() {

           }
       });

为什么相机不沿着这些位置移动。位置数组中有8个位置。为什么相机不更新?
编辑:我已经将animatecamera添加到回调中,但是回调从未被调用我重新发布了当前的实现,我在回调中记录了日志,它从未被调用?

CameraPosition cameraPosition =
                new CameraPosition.Builder()
                        .target(new LatLng(currentRoute.locations.get(1).getLatitude(),
                                currentRoute.locations.get(1).getLongitude()))
                        .tilt(60)
                        .bearing((float)currentRoute.getRouteEdges().getFirst().getHeading(currentRoute.getStart(), currentRoute.getFinish())-40)
                        .zoom(20)
                        .build();

        CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));

        turnByTurnMap.animateCamera(update,
                3000,
                routeAnimationCancelableCallback);

        routeAnimationCancelableCallback = new GoogleMap.CancelableCallback() {

            @Override
            public void onCancel() {

            }
            @Override
            public void onFinish() {
                Log.d(TAG, "onFinish: here");
                if(currentPosition<currentRoute.locations.size()-1){
                    float bearing = HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
                            currentRoute.locations.get(currentPosition+1).getLongitude()).bearingTo(HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
                            currentRoute.locations.get(currentPosition+2).getLongitude()));
                    CameraPosition cameraPosition =
                            new CameraPosition.Builder()
                                    .target(new LatLng(currentRoute.locations.get(currentPosition+1).getLatitude(),
                                            currentRoute.locations.get(currentPosition+1).getLongitude()))
                                    .tilt(60)
                                    .bearing(bearing)
                                    .zoom(10)
                                    .build();
                    CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));

                    turnByTurnMap.animateCamera(update,
                            3000,
                            routeAnimationCancelableCallback);
                    currentPosition++;
                }

            }
        };
v1l68za4

v1l68za41#

考虑到第二个代码,只需将初始调用移动到 animateCamera 设置后 routeAnimationCancelableCallback . 这还包括要调用的初始修复 animateCamera 在回调中。

// initial call to animateCamera was here...

    routeAnimationCancelableCallback = new GoogleMap.CancelableCallback() {

        @Override
        public void onCancel() {

        }
        @Override
        public void onFinish() {
            Log.d(TAG, "onFinish: here");
            if(currentPosition<currentRoute.locations.size()-1){
                float bearing = HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
                        currentRoute.locations.get(currentPosition+1).getLongitude()).bearingTo(HelperMethods.latLongToLocationDouble(currentRoute.locations.get(currentPosition+1).getLatitude(),
                        currentRoute.locations.get(currentPosition+2).getLongitude()));
                CameraPosition cameraPosition =
                        new CameraPosition.Builder()
                                .target(new LatLng(currentRoute.locations.get(currentPosition+1).getLatitude(),
                                        currentRoute.locations.get(currentPosition+1).getLongitude()))
                                .tilt(60)
                                .bearing(bearing)
                                .zoom(10)
                                .build();
                CameraUpdate update = (CameraUpdateFactory.newCameraPosition(cameraPosition));

                turnByTurnMap.animateCamera(update,
                        3000,
                        routeAnimationCancelableCallback);
                currentPosition++;
            }

        }
    };

    // and moved to here...

    turnByTurnMap.animateCamera(update,
            3000,
            routeAnimationCancelableCallback);

相关问题