Reputation: 295
I dont want to change the marker's image I just want to add an image to the title so it looks nice
something like this "Read More" image..
is there any way to do so
thanks
Upvotes: 1
Views: 2193
Reputation: 4005
Title is called InfoWindow
. To achieve your custom window, you need:
1) Create class which implement GoogleMap.InfoWindowAdapter
interface. Something like this (in this case just TextView
):
public class MapItemAdapter implements GoogleMap.InfoWindowAdapter {
TextView tv;
public MapItemAdapter(Context context) {
tv = new TextView(context);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
tv.setLayoutParams(lp);
tv.setGravity(Gravity.CENTER);
}
@Override
public View getInfoWindow(Marker marker) {
tv.setText(marker.getTitle());
return tv;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
2) Set adapter to GoogleMap
you've received in onMapReady()
callback:
@Override
public void onMapReady(final GoogleMap map) {
...
map.setInfoWindowAdapter(new MapItemAdapter(this));
...
}
Upvotes: 2