public void marker1(final List<String> listName,
final List<String> listIllness, final List<String> listIC,
final List<String> listElderlyimage, List<String> listArduinomac,
List<String> listLat, List<String> listLong) {
Log.e("", Integer.toString(listName.size()));
for (int i = 0; i < listName.size(); i++) {
name = listName.get(i);
ic = listIC.get(i);
illness = listIllness.get(i);
Double Lat = Double.parseDouble(listLat.get(i));
Double Long = Double.parseDouble(listLong.get(i));
MarkerOptions marker = new MarkerOptions().position(new LatLng(Lat,
Long));
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
infoWindowAdapter = new MarkerInfoWindowAdapter();
googleMap.setInfoWindowAdapter(infoWindowAdapter);
infoWindowAdapter.setName(name);
infoWindowAdapter.setIC(ic);
infoWindowAdapter.setIllness(illness);
googleMap.addMarker(marker);
}// for loop
}// marker1
列表的最後一個元素。這是我使用自定義信息窗口只顯示在android系統
class MarkerInfoWindowAdapter implements InfoWindowAdapter {
private View inflatedView;
private String name, ic, illness;
public void setName(String name) {
this.name = name;
}
public void setIC(String ic) {
this.ic = ic;
}
public void setIllness(String illness) {
this.illness = illness;
}
MarkerInfoWindowAdapter() {
inflatedView = getActivity().getLayoutInflater().inflate(
R.layout.custom_info_contents, null);
}
@Override
public View getInfoContents(Marker marker) {
setInfo(marker, inflatedView);
return inflatedView;
}
@Override
public View getInfoWindow(Marker marker) {
setInfo(marker, inflatedView);
return inflatedView;
}
private void setInfo(Marker marker, View view) {
TextView txtname = (TextView) view
.findViewById(R.id.txtPatientName);
TextView txtIC = (TextView) view.findViewById(R.id.txtIC);
TextView txtIllness = (TextView) view.findViewById(R.id.txtIllness);
txtname.setText(name);
txtIC.setText(ic);
txtIllness.setText(illness);
Log.e("<>", txtname.toString());
}
}
您好定製infowindowadapter,我不知道爲什麼,每當我點擊該標記,它不斷顯示同一人的信息。我不確定哪裏出了問題。請幫幫我!謝謝。
所以我可以有一個標記列表?並將它們傳遞到自定義信息窗口中? – 2014-10-02 02:43:24
@MarcusKoh:'InfoWindowAdapter'需要一種方法來根據提供給'getInfoWindow()'或'getInfoContents()'的'Marker'來查找要顯示的細節。你如何實現這一切取決於你。 – CommonsWare 2014-10-02 11:20:29