Android-maps-utils: Cluster / Marker showing inconsitent behaviour

Created on 6 Mar 2014  路  5Comments  路  Source: googlemaps/android-maps-utils

Hey there,
I'm using ClusterManager to add markers/clusters on my map and i'm fetching my LatLong data through server via AsyncTask, and i'm getting inconsistent behaviour,
Sometimes the marker and cluster are rendering perfectly all-right but some times they don't appear unless I zoom in or zoom out the map ..

Help would be much appreciated as i've already wasted my alot of time in searching .

Most helpful comment

Are you calling clusterManager.cluster() after you call addItems?

All 5 comments

Thanks for the report - do you have a minimal test case I can debug against?

Thanks for the quick response :)
so the case is.
I initialize map and add clusterMangaer and hook listners and then call addItems function in which i'm starting AsyncTask passsing clustermanger object to it and there i'm getting coordinates data via http request and on success of request m adding coordinates in clustermanger .. It works fine some of time but sometimes markers don't appear untill i zoom in or zoom out the map .. i've debugged i'm getting no error in data and even markers are there but they only show up on zoom in or zoom out .

Are you calling clusterManager.cluster() after you call addItems?

great .. i wasn't .. thanks alot ..saved my day .. closing the issue.. thanks alot once again :)

I have a method that _setMarkersOnMap(){...}_
1.At first I clear items _mClusterManager?.clearItems()_
2.I add items to cluster manager by _mClusterManager?.addItem(poi)_
3.Simultanieously i the same loop I take only first 6 items in order to count _LatLngBounds boundBuilder.include(poi.latLng)_

  1. When I leave loop I animateCamer according to the LatLngBounds
  2. I call _mClusterManager?.cluster()_

When I call the function first time it works fine, after I call it again markers are not present unless I zoom out - what force IdleListener to make clustering. My Code is

protected fun setMarkersOnMap(poiList : List<POI>){
        clearMap()
        if(poiList.isEmpty()){
            return
        }

        val boundBuilder  : LatLngBounds.Builder = LatLngBounds.builder()

        poiList.forEachIndexed { index, poi -> run{
            poi.icon = getIconForType(poi.typeName)
            poi.setAnchor(0.5f, 0.6f)

             mClusterManager?.addItem(poi)

            // Add new coordinates in order to establish map zoom
            if (index < 6)
                boundBuilder.include(poi.latLng)
        }}

       mClusterManager?.cluster()
        // Adjust Map zoom to Marker position
        val mapPadding = Tools.dpToPx(12) // offset from edges of the map in pixels
        val mCurrentLatLng : LatLng  = LatLng(mLocation.latitude, mLocation.longitude)
        boundBuilder.include(mCurrentLatLng)
        val latLngBounds = boundBuilder.build()


        mGoogleMap?.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, mapPadding), cameraUpdateListener)

            if(!isClusterManagerListenToMap){
                handler.postDelayed({
                    // listen for changes. After Zoom will be updated we set ClusterManager listener
                    isClusterManagerListenToMap = true
                    mGoogleMap?.setOnCameraIdleListener(mClusterManager)
                    mClusterManager?.cluster()
                }, 500)
            }else{
                handler.postDelayed({
                    mClusterManager?.cluster()
                }, 500)
            }
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

SeijiIto picture SeijiIto  路  7Comments

CodeHore picture CodeHore  路  4Comments

air89 picture air89  路  6Comments

patriotaSJ picture patriotaSJ  路  7Comments

WeiLinJoe picture WeiLinJoe  路  4Comments