首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GoogleMaps CancelableCallback不会更改我的相机角度和位置。我做错了什么?

GoogleMaps CancelableCallback不会更改我的相机角度和位置。我做错了什么?
EN

Stack Overflow用户
提问于 2020-12-18 23:45:07
回答 1查看 43关注 0票数 0

我已经添加了放置在onMapReady()中的相机位置和动画回调。

代码语言:javascript
复制
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添加到回调中,但是回调从未被调用过。我重新发布了当前的实现,我已经在回调中登录,但它从未被调用过?

代码语言:javascript
复制
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++;
                }


            }
        };
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-21 02:22:14

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

代码语言:javascript
复制
    // 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65359906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档