当我在点击标记时使用自定义弹出窗口时,我无法通过动画 google 相机来放大相机

I am not able to zoom camera in by animating google camera when i am using custom popup on click of marker

In on mapReady function of google map i have written below: it basically forms cluster of marker location data and pass it to the cluster manager How can i do googleMap.animateCamera() on getInfoWindow() as it not working to get zoomed in by animating camera on click of marker with popup opened.

mClusterManager = new ClusterManager<>(getActivity(), mMap);
        mClusterManager.setAlgorithm(getAlgorithm());
        mClusterManager.setRenderer(new MyRenderer(getActivity(), mMap));
        mClusterManager.setAnimation(true);
        //To set custom dialog on marker click
        mClusterManager.getMarkerCollection().setInfoWindowAdapter(new PubLocationCustomClusterInfoView(this, getActivity(), pubArrayList, this, getMap()));
        mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<PubLocation>() {
            @Override
            public boolean onClusterItemClick(PubLocation item) {
                return false;
            }
        });

PubLocationCustomClusterInfoView.java -- This is my custom view for marker popup where i want to zoom in by animating google camera but im unable to.

public class PubLocationCustomClusterInfoView implements GoogleMap.InfoWindowAdapter {
    private View clusterItemView;
    private static final String TAG = "PubLocationCustomCluste";
    Context context;
    private OnInfoWindowElemTouchListener infoButtonListener,orderFromPubListener;
    ArrayList<PubData.Pub> pubArrayList;
    MarkerInfoWindow markerInfoWindowlistner;
    MapMarkerOnClickListener mapMarkerOnClickListener;
    GoogleMap googleMap;

    public PubLocationCustomClusterInfoView(MarkerInfoWindow markerInfoWindow, Context context, ArrayList<PubData.Pub> pubArrayList, MapMarkerOnClickListener mapMarkerOnClickListener,GoogleMap googleMap) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        this.context=context;
        this.markerInfoWindowlistner=markerInfoWindow;
        this.pubArrayList=pubArrayList;
        clusterItemView = layoutInflater.inflate(R.layout.marker_info_window, null);
        this.mapMarkerOnClickListener = mapMarkerOnClickListener;
        this.googleMap=googleMap;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        Log.i(TAG, "getInfoWindow: "+marker);

        return null;
    }


    @Override
    public View getInfoContents(Marker marker) {
        Log.i(TAG, "getInfoContents: "+marker);

        PubLocation pubLocation = (PubLocation) marker.getTag();
//        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(),13));
        if (pubLocation == null) return clusterItemView;
        TextView itemNameTextView = clusterItemView.findViewById(R.id.itemNameTextView);
        TextView itemAddressTextView = clusterItemView.findViewById(R.id.itemAddressTextView);
        ImageButton pub_info=(ImageButton)clusterItemView.findViewById(R.id.pub_info);
        Button order_from_pub=(Button) clusterItemView.findViewById(R.id.order_from_pub);

        this.infoButtonListener = new OnInfoWindowElemTouchListener(pub_info) //btn_default_pressed_holo_light
        {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the button
                Log.i(TAG, "onClickConfirmed: ");
                Intent intent=new Intent(context,PubInfoActivity.class);
                intent.putExtra(Constants.PUB_ID_KEY, pubLocation.getPubId());
                context.startActivity(intent);
            }
        };
        pub_info.setOnTouchListener(infoButtonListener);

        this.orderFromPubListener = new OnInfoWindowElemTouchListener(order_from_pub) //btn_default_pressed_holo_light
        {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the button
                for (int i = 0; i < pubArrayList.size(); i++) {
                    if (pubArrayList.get(i).getPubId().equals(pubLocation.getPubId())) {
                       mapMarkerOnClickListener.onMarkerClick(pubArrayList.get(i),v);
                        break;
                    }
                }
            }
        };
        order_from_pub.setOnTouchListener(orderFromPubListener);
        itemNameTextView.setText(pubLocation.getTitle());
        itemAddressTextView.setText(pubLocation.getSnippet());
        markerInfoWindowlistner.setMarkerInfoWindow(clusterItemView,marker);
        return clusterItemView;
    }
}

终于找到了这个问题的解决方案

首先设置clustermanager映射如下:

getMap().setOnMarkerClickListener(mClusterManager);

点击标记后,您只需要通过添加以下条件来 return 为真,并将缩放级别传递给 google 地图摄像机

mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<PubLocation>() {
            @Override
            public boolean onClusterItemClick(PubLocation item) {
                Log.i(TAG, "onClusterItemClick: ");
                for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                    if (marker.getPosition().latitude == item.getPosition().latitude &&
                            marker.getPosition().longitude == item.getPosition().longitude) {
                        marker.showInfoWindow();
                    }
                }

                CameraUpdate location = CameraUpdateFactory.newLatLngZoom(item.getPosition(), 10);
                getMap().animateCamera(location, new GoogleMap.CancelableCallback() {
                    @Override
                    public void onFinish() {
                        getMap().animateCamera(CameraUpdateFactory.newLatLng(getMap().getProjection().fromScreenLocation(mappoint)));
                    }

                    @Override
                    public void onCancel() {

                    }
                });
                return true;
            }
        });