以下是我尝试添加两个标记的示例代码。我在谷歌地图上添加了2个标记。我必须为两个标记显示不同的自定义信息窗口,我该如何在Android中执行此操作?
以下是为该
编写的代码mMap.addMarker(new MarkerOptions()
.position(position).title(v_nam)
.snippet(v_loc)
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))).showInfoWindow();
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
String t1 = "<font color='#0000FF'> Vehicle :</font>";
String t2 = "<font color='#0000FF'> Vehicle Type :</font>";
String t4 = "<font color='#0000FF'> Speed :</font>";
String t5 = "<font color='#0000FF'> Location Address :</font>";
String t6 = "<font color='#0000FF'> Ignition :</font>";
String t7 = "<font color='#0000FF'> Live Date And Time :</font>";
TextView tvV = (TextView) v.findViewById(R.id.tv_vehicle);
tvV.setText(Html.fromHtml(t1 + v_nam));
TextView tvVT = (TextView) v.findViewById(R.id.tv_vehicletype);
tvVT.setText(Html.fromHtml(t2 + v_vt));
TextView tvDt = (TextView) v.findViewById(R.id.tv_dateandtime);
tvDt.setText(Html.fromHtml(t7 + v_ld));
TextView tvLoc = (TextView) v.findViewById(R.id.tv_location);
tvLoc.setText(Html.fromHtml(t5 + v_loc));
TextView tvSped = (TextView) v.findViewById(R.id.tv_direction);
tvSped.setText(Html.fromHtml(t4 + v_dir));
TextView tvign = (TextView) v.findViewById(R.id.tv_ignition);
tvign.setText(Html.fromHtml(t6 + v_ig));
return v;
}
});
mMap.moveCamera( CameraUpdateFactory.newLatLngZoom(position , 13.0f) );
}
drawPolyLineOnMap(Points);
Log.i("history la", String.valueOf(Points));
答案 0 :(得分:0)
标记您的标记并在getInfoContents()方法中使用它。
@Override
public View getInfoContents(Marker marker) {
if (marker.getTag() == YOUR_FIRST_MARKER_TAG) {
View v = getLayoutInflater().inflate(R.layout.custom_info_contents_FOR_FIRST_MARKER, null);
//MORE CODE
return v;
} else {
View v = getLayoutInflater().inflate(R.layout.custom_info_contents_FOR_SECOND_MARKER, null);
//MORE CODE
return v;
}
}