0

In my project I am using Google Map V2 and Map Utils for clustering map from this library: https://github.com/googlemaps/android-maps-utils . I have use STOMP on my project and whenever I receive new data I need to update the marker, and I have done it by removing all marker from cluster manager and re-adding them. But now my issue is whenever a a user clicks on marker a InfoWindow of marker is shown to the user and after than If I receive a data new data a InfoWindow will be closed due to calling mClusterManager.cluster(); function. Now, My question is how to show a InfoWindow after Cluster is refreshed.

Below are my codes:

 googleMap.setOnMarkerClickListener(mClusterManager);

        addClusterMarkers(mClusterManager);
        mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(new  CustomAdapterInfoWindow());

 mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<AppClusterItem>() {
        @Override
        public boolean onClusterItemClick(AppClusterItem appClusterItem) {
            showingInfoWindowId = appClusterItem.getmId();
            return false;
        }
    });
    googleMap.setOnMarkerClickListener(mClusterManager);


  //New Data Update
 on NewDataReceived(String _id){
  mClusterManager.clearItems();
                            addClusterMarkers(mClusterManager);
                            mClusterManager.cluster();
                            try {
                                Log.d(Constants.TAG, appClusterItemList.size() + "Showing Info Window" + activeDataKey.get(_id));
                                render.getMarker(appClusterItem[0]).showInfoWindow();
                            } catch (Exception e) {
                                Log.d(Constants.TAG, "" + e);
                            }
                            mClusterManager.cluster();
                        }
                    });

}

I want to show an ShowInfoWindow() after data is received if until user click the marker again. (Clicking marker again will hide showInfoWindow (Default))

If anyone can answer my previous question I would be happy, because I want it to do better way, just updating single item. see here : Update single item GoolgeMap Cluster

Queendevelopers
  • 183
  • 3
  • 20

1 Answers1

0

I do this in my app when I want to update a single marker, so I'm not sure this can be useful to you as it seems you're calling a whole new set of clusterItems.

I have the following fields in my class:

//declaring a clicked item
private PropertyModel clickedPropertyModelClusterItem;

private Marker clickedMarker;

When I click on infoWindow, this method get called:

mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<PropertyModel>(){
        @Override
        public boolean onClusterItemClick(PropertyModel propertyModelItem){
            clickedPropertyModelClusterItem = propertyModelItem;
            return false;
        }
    });

In my method getInfoContents I assign the Marker in parameter to the created field in order to keep trace of it:

@Override
    public View getInfoContents(final Marker marker) {

    clickedMarker = marker;

    //set the values of InfoWindows as usual

}

Now, instead of calling mClusterManager.clearItems(), I update my clickedPropertyModelClusterItem:

clickedPropertyModelClusterItem.setTitle(propertyModel.getTitle());

Finally, I call the showInfoWindow method on the marker:

//update the InfoWindow
clickedMarker.showInfoWindow();

Hope this can help you.

makles
  • 55
  • 1
  • 7
  • Hi bro... Thanks for your answer but for me it won't work because, after I call mClusterManager.ClearItems(); all the marker data will be clear from ClusterManager. hence, after adding them all , if I called clickedMarker.showInfoWindow(); (which was my old marker) this will obviously throws a nullpointer exception due to old marker not found. – Queendevelopers Jan 08 '19 at 05:36