For this you have to create a% custom InfoWindowAdapter
, containing the reference to ImageView
and load the images from the resources, this is an example:
public class CustomInfoWindowAdapter implements InfoWindowAdapter{
private static final String TAG = "CustomInfoWindowAdapter";
private LayoutInflater inflater;
public CustomInfoWindowAdapter(LayoutInflater inflater){
this.inflater = inflater;
}
@Override
public View getInfoContents(final Marker m) {
//Carga layout personalizado.
View v = inflater.inflate(R.layout.infowindow_layout, null);
Drawable myDrawable = getResources().getDrawable(R.drawable.mi_imagen);
//Carga imagen.
((ImageView)v.findViewById(R.id.info_window_image)).setImageDrawable(myDrawable);
((TextView)v.findViewById(R.id.info_window_city)).setText("Sidney");
((TextView)v.findViewById(R.id.info_window_lat)).setText("-10.79");
((TextView)v.findViewById(R.id.info_window_lon)).setText("-77.71");
return v;
}
@Override
public View getInfoWindow(Marker m) {
return null;
}
}
To load the custom infoWindow, you do it to your GoogleMap using the method setInfoWindowAdapter()
where you assign the InfoWindowAdapter
personalized.
myGoogleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(getActivity())));