我如何在集群管理器的标记中调用showinfowindow()? [英] How I can call showinfowindow() in a marker within cluster manager?

查看:134
本文介绍了我如何在集群管理器的标记中调用showinfowindow()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用群集中的标记(谷歌地图),我在调用onclick方法时显示信息窗口没有问题。
问题是,我无法找到如何使用方法showInfoWindow(),因为我在标记上打开信息而不用点击。



当我使用标记时,可以使用标记

  marker = map.addMarker(new MarkerOptions()
.position(position)
.snippet(info));

然后我打电话给

  marker.showInfoWindow(); 

我如何使用集群管理器中映射的标记(ClusterItem) ?

  MarkCluster cluster = new MarkCluster(Lat,Lon,info); 
mClusterManager.addItem(cluster);

这是我想要显示的标记infoWindow

解决方案

试试这个,当我使用群集的时候,我做了地图标记的引用:



创建 ClusterManager 时,它总是创建并使用 DefaultClusterRenderer .setRenderer()方法并将它传递给您自己的 ClusterRenderer 实现。如果你让 ClusterManager 创建它自己的 DefaultClusterRenderer ,那么关键是明确地添加它,这样你可以保留一个引用(因为 ClusterManager 没有getter方法,所以你可以使用 ClusterRenderer > using):

  mClusterManager =新的ClusterManager< ClusterItem>(getActivity(),mMap); 
mRenderer = new DefaultClusterRenderer(getActivity(),mMap,mClusterManager);
mClusterManager.setRenderer(mRenderer);
mClusterManager.addItem(ClusterItem);

然后当您需要访问标记时,传递 ClusterRenderer 与标记关联的 ClusterItem 。您用于查找标记的 ClusterItem 将传递给 ClusterManager < ClusterItem / code>将标记添加到群集中:

  Marker marker = mRenderer.getMarker(ClusterItem); 
if(marker!= null){
marker.showInfoWindow();

标记对象如果标记尚未在地图上呈现,那么它将为null,因此请务必在使用标记对象之前检查它是否为空。



如果您确定当您调用 .getMarker()并且marker仍为null时,标记已放置在地图上,然后覆盖 .equals()方法
用于实现 ClusterItem 接口,以确保能够找到正确的 ClusterItem 由渲染器持有的对象。

I'm working with markers in a cluster (google maps), I have no problem in showing an info window when calling the onclick method. The problem is that I can't find how to use the method showInfoWindow() as I do on a marker to open the info without giving click.

When I use a marker

marker = map.addMarker(new MarkerOptions()
                    .position(position)
                    .snippet(info));

then I call

marker.showInfoWindow();

how I can do the same with a marker (ClusterItem) that is on the map within the cluster manager?

MarkCluster cluster = new MarkCluster(Lat, Lon, info);
mClusterManager.addItem(cluster);

It is the marker that I want to show infoWindow

解决方案

Try this, its what I did to get references to map markers when using clustering:

When you create a ClusterManager it always creates and uses an instance of the DefaultClusterRenderer if you don't call the .setRenderer() method and pass it an instance of your own ClusterRenderer implementation. If you are letting the ClusterManager create its own DefaultClusterRenderer the key is to add it explicitly so that you can keep a reference to it (because the ClusterManager has no getter method so you can get a reference to the ClusterRenderer its using):

mClusterManager = new ClusterManager<ClusterItem>(getActivity(), mMap);
mRenderer = new DefaultClusterRenderer(getActivity(), mMap, mClusterManager); 
mClusterManager.setRenderer(mRenderer); 
mClusterManager.addItem(ClusterItem);  

Then when you need access to a marker pass the ClusterRenderer the ClusterItem associated with the marker. The ClusterItem you use to find the marker will be the ClusterItem you passed to the ClusterManager to add the marker to the cluster originally:

Marker marker = mRenderer.getMarker(ClusterItem);
if(marker != null){
    marker.showInfoWindow();
}

The Marker object will be null if the marker has not been rendered on the map yet so be sure to check that the marker object is not null before using it.

If you are certain the marker has been placed on the map when you call .getMarker() and marker is still null then override the .equals() method in the object use to implement the ClusterItem Interface to make sure you can find the correct ClusterItem object held by the renderer.

这篇关于我如何在集群管理器的标记中调用showinfowindow()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆