当用户点击制造商时,我设置CustomInfoWindow
为调用。我不会在创建时调用它,Map
而是仅在用户单击Marker
.
我有不同的覆盖,那些有不同的 infoWindows 实现覆盖类构建infoWindow
如下。
public void onTap(AndroidMapOverlayItem item) {
String overlayType = "";
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
/*
* some code to find overlayType
*/
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
if ("mylocation".equalsIgnoreCase(overlayType)) {
// set title
((TextView)infoWindow.findViewById(R.id.title)).setText("Title");
// set distance
((TextView)infoWindow.findViewById(R.id.text)).setText(display);
}
return infoWindow;
}
});
}
下面是我的活动类,它选择用户点击并找到哪个标记。根据标记,我称其为相关的覆盖类。该覆盖类具有要在信息窗口中显示的信息。活动课。
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.setOnMarkerClickListener(this);
@Override
public boolean onMarkerClick(final Marker marker) {
Log.d(TAG,"Inside onMakerClick "+marker);
/*
* find the relevant overlay class and try to fire it's onTap event.
* onTap event has what needs to be done with specific marker.
* Different marker has different information to show.
*
*/
overlay.onTap(overlayItem);
return true;
}
这是我想要的,因为当我在第一个实例中设置 CustomInfowindow 时,所有标记都显示相同的信息。