Android maps markers show on map only after zooming change

六月ゝ 毕业季﹏ 提交于 2019-12-23 08:07:07

问题


I made simple application where I get markers based on screen coordinates from the server. Problem is that markers doesn't appear on map immediately. User user must zoom in or zoom out only then marker is visible. Why is that? Is it possible to show marker as soon when marker data is downloaded from server? Or is it possible to somehow refresh map? I know that in previous version there was method map.invalidate() that is basically what I need to have now. Unfortunately this method is not available now.

I will add code snippet how my markers is added

@Override
        protected void onPostExecute(ArrayList<MarkerItemData> markerItemData) {
            super.onPostExecute(markerItemData);
            if(markerItemData != null) {
                mClusterManager.addItems(markerItemData);
            }
        }

回答1:


It needs re-clustering again.

mClusterManager.addItems(markerItemData);
mClusterManager.cluster();

Because, when you add or remove an ClusterItem (MarkerItemData), it just performs the algorithm and calculates clusters. But does not render on map

Finally, ClusterManager listens onCameraIdle event(includes zoom events) and invokes cluster() method internally. This is the answer of user must zoom in or zoom out only then marker is visible.




回答2:


From the javadoc here, you need to recluster your markers after adding them to your ClusterManager doing mClusterManager.cluster().



来源:https://stackoverflow.com/questions/41705216/android-maps-markers-show-on-map-only-after-zooming-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!