Android Maps Utils Clustering show InfoWindow

前端 未结 3 1616
天命终不由人
天命终不由人 2020-11-30 06:17

I am planning to use the google maps marker clustering available in the utils library, but the google example app only shows marker clusters without any infoWindow. I am won

3条回答
  •  被撕碎了的回忆
    2020-11-30 06:52

    You could consider the following approach:

    public void initilizeMap() {
                googleMap = mFragment.getMap();
                googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
                googleMap.getUiSettings().setZoomControlsEnabled(true`enter code here`); // true to`enter code here`
                googleMap.getUiSettings().setZoomGesturesEnabled(true);
                googleMap.getUiSettings().setCompassEnabled(true);
                googleMap.getUiSettings().setMyLocationButtonEnabled(true);
                googleMap.getUiSettings().setRotateGesturesEnabled(true);
                if (googleMap == null) {
                    Toast.makeText(getActivity(), "Sorry! unable to create maps",
                            Toast.LENGTH_SHORT).show();
                }
                mClusterManager = new ClusterManager(getActivity(),   googleMap );
    //          googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
                googleMap.setOnMapLoadedCallback(this);
                googleMap.setMyLocationEnabled(true);
                googleMap.setBuildingsEnabled(true);
                googleMap.getUiSettings().setTiltGesturesEnabled(true);
    
    MyItem offsetItem = new MyItem(Double.parseDouble(outletList.get(i).getMap_latitude()),
                                               Double.parseDouble(outletList.get(i).getMap_longitude()), title , address);
                mClusterManager.addItem(offsetItem);
                googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(offsetItem));
    
    }
    
    
        private class CustomInfoWindowAdapter implements InfoWindowAdapter {
            Marker marker;
            private View view;
            private MyItem items;
    
            public CustomInfoWindowAdapter(MyItem item) {
                view = getActivity().getLayoutInflater().inflate(
                        R.layout.custom_info_window, null);
                this.items = item;
            }
    
            @Override
            public View getInfoContents(Marker marker) {
    
                if (marker != null && marker.isInfoWindowShown()) {
                    marker.hideInfoWindow();
                    marker.showInfoWindow();
                }
                return null;
            }
    
            @Override
            public View getInfoWindow(final Marker marker) {
                this.marker = marker;
    
                String url = null;
    
                if (marker.getId() != null && markers != null && markers.size() > 0) {
                    if (markers.get(marker.getId()) != null
                            && markers.get(marker.getId()) != null) {
                        url = markers.get(marker.getId());
                    }
                }
    
                final ImageView image = ((ImageView) view.findViewById(R.id.badge));
    
                if (url != null && !url.equalsIgnoreCase("null")
                        && !url.equalsIgnoreCase("")) {
                    imageLoader.displayImage(url, image, options,
                            new SimpleImageLoadingListener() {
                                @Override
                                public void onLoadingComplete(String imageUri,
                                        View view, Bitmap loadedImage) {
                                    super.onLoadingComplete(imageUri, view,
                                            loadedImage);
                                    getInfoContents(marker);
                                }
                            });
                } else {
                    image.setImageResource(R.drawable.ic_launcher);
                }
    
                final String title = items.getTitle();
                Log.e(TAG, "TITLE : "+title);
                final TextView titleUi = ((TextView) view.findViewById(R.id.title));
                if (title != null) {
                    titleUi.setText(title);
                } else {
                    titleUi.setText("");
                }
    
                final String address = items.getAddress();
                final TextView snippetUi = ((TextView) view
                        .findViewById(R.id.snippet));
                if (address != null) {
                    snippetUi.setText(address);
                } else {
                    snippetUi.setText("");
                }
    

提交回复
热议问题