不同的标记显示相同的infowindow内容android谷歌地图v2

时间:2013-11-04 08:07:49

标签: android google-maps-android-api-2 marker

根据Markers中显示的不同信息,我有不同的custom infowindow。为此,我为每个infowindow内容使用了不同的类。

我可以在地图中看到不同的Markers。但我点击它们,只显示最后建立的标记信息。基本上infowindow内容是相同的。 另外我注意到,当我点击时,它不会调用相关的信息窗口,而是调用最后创建的信息窗getInfoContents(Marker arg0)。但我收到了getInfoContents(Marker arg0)内最后添加标记的正确标记。

我们只能为地图中的所有标记实现一个infowindow实现?基于标记识别我应该实现不同的内容吗?

标记类型A实现

 public class MapGoogleOverlayV2 {

    private ViewGroup infoWindow;

    public boolean onTap() {


    infoWindow  = (ViewGroup)((Activity)mContext).getLayoutInflater().inflate(R.layout.info_window_layout, null);


    /*Custom info window implementation is below */
    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {

            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {

            // set title
            ((TextView)infoWindow.findViewById(R.id.title)).setText("Test text");

            // set freeText
            ((TextView)infoWindow.findViewById(R.id.text)).setText(Long.toString("1"));


              return infoWindow;

        }
    });
   }
}

Marker B在另一个具有不同信息的类中实现。 我打电话给onTap()

我通过调用自己的实现创建两个具有不同信息的标记,并在地图中显示。

唯一的问题是它们都显示相同的信息,这是最后一个标记的信息。

1 个答案:

答案 0 :(得分:1)

Setters(和GoogleMap.setInfoWindowAdapter似乎是一个制定者)取代以前的东西。

如果您在这两个课程中致电onTap,则只有最后一个InfoWindowAdapter存活。

相反,您只需设置一个InfoWindowAdapter,并根据Marker参数(getInfoContents)确定需要显示信息窗口的Marker arg0