Different markers show same infowindow content android google map v2

社会主义新天地 提交于 2019-12-25 02:44:06

问题


I have different Markers based on their different information to show in custom infowindow. For that I have use different class for each infowindow content.

I can see different Markers in my map. But I tap on them, only the lastly built marker's information is showing. Basically the infowindow content is same. Also I noted that when I tap, it does not call the relevent infowindow instead its calling lastly created infowindow's getInfoContents(Marker arg0). But I receive the correct marker inside to getInfoContents(Marker arg0) to the lastly added marker.

We can have only one infowindow implementation for all the markers in the map? And based on the marker identification should I implement the different contents?

Marker type A implementation

 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 implemented in another class with different info. and I am calling onTap()

I create two markers with different information by calling their own implementation and display that in map.

only problem is they both show same information which is last marker's information.


回答1:


Setters (and GoogleMap.setInfoWindowAdapter seems to be a setter) replace what was there before.

If you call onTap in both classes, only the last InfoWindowAdapter survives.

Instead you need to set only one InfoWindowAdapter and decide for which Marker you need to show info window based on getInfoContents parameter (Marker arg0).



来源:https://stackoverflow.com/questions/19763763/different-markers-show-same-infowindow-content-android-google-map-v2

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