I know there are a few threads around on this topic but i havent yet found a good enough solution.
I NEED to place a marker over the top of all other markers. How do
Aiden Fry's answer works if you do actually display an InfoWindow. If you don't, the marker won't come to the front. Here is a hack to make it come to the front anyway:
Create a custom InfoWindowAdapter that displays a 0dp info window:
public class MapWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Context context = null;
public MapWindowAdapter(Context context) {
this.context = context;
}
// Hack to prevent info window from displaying: use a 0dp/0dp frame
@Override
public View getInfoWindow(Marker marker) {
View v = ((Activity) context).getLayoutInflater().inflate(R.layout.no_info_window, null);
return v;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
Here is the code for the layout:
When you set up your map, set the adapter and custom InfoWindowAdapter and OnMarkerClickListener (using showInfoWindow and returning true as AIden Fry advised):
mMap.setInfoWindowAdapter(new MapWindowAdapter(this));
//Call showInfoWindow to put marker on top of others.
myMarker.showInfoWindow();
This is not beautiful, but I didn't find any other way to deal with z-indexing without using info windows.