我的谷歌地图上有一些标记,但所有标记都有羞耻信息如何为不同的标记制作不同的信息?
for (Station station : stationsListResponse.data.stations) {
final Station st = station;
map.addMarker(new MarkerOptions().position(new LatLng(station.getLatitude(), station.getLongitude())));
map.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window, null);
TextView info= (TextView) v.findViewById(R.id.info);
info.setText(st.street+"\n"+st.city);
return v;
}
});
}
答案 0 :(得分:2)
所有标记具有相同信息的原因是因为您将Station st = station声明为final。
而是将您希望显示的信息设置为标记的属性,然后在调用getInfoContents(..)时可以访问它。
for (Station station : stationsListResponse.data.stations)
{
map.addMarker(new MarkerOptions().position(new LatLng(station.getLatitude(), station.getLongitude())).snippet(station.street+"\n"+station.city));
}
map.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window, null);
TextView info= (TextView) v.findViewById(R.id.info);
info.setText(marker.getSnippet());
return v;
}
});
答案 1 :(得分:0)
这样做
map.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public View getInfoWindow(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window, null);
TextView info= (TextView) v.findViewById(R.id.info);
info.setText(st.street+"\n"+st.city);
return v;
}
});