Android - Maps v2 - How to arrange z-axis of last marker drawn

972 Views Asked by At

Ive put together a tool in an app Im building that uses the v2 version of the maps on android and when markers are very close to one another they will draw ontop of one another which isnt a problem but what Id like to have happen at the least is for the last marker drawn to appear on the top.

Is there a way to make sure that the last marker drawn is shown on top of the rest or am I at the mercy of the systems decision making when it comes to showing markers that are to closely grouped together.

2

There are 2 best solutions below

0
On BEST ANSWER

For now I just ended up using

marker.showInfoWindow();

It gives me the exact behavior I want which is keeping the last drawn marker to appear on the very top of the other markers on screen.

On a side note it does open the info window but if I really wanted to I could just set a custom layout and make it null for the info window under a certain condition but for my needs it actually works out good that the window opens.

0
On

As James already wrote, showing an InfoWindow will do the trick.

You can "show" an invisible InfoWindow by using your own adapter:

public class InfoWindowAdapter implements GoogleMap.InfoWindowAdapter{


private final View mWindow;

public InfoWindowAdapter(Activity activity) {
    mWindow = App.activity.getLayoutInflater().inflate(R.layout.custom_info_window,
            null);
}

@Override
public View getInfoContents(Marker mark) {
    return null;
}

@Override
public View getInfoWindow(Marker marker) {
    render(marker, mWindow);
    return mWindow;
}

private void render(Marker marker, View view) {
    //do nothing
}

}

Set this to the map:

map.setInfoWindowAdapter(new InfoWindowAdapter(activity));

And show the InfoWindow:

 currentlySelectedMarker.setSnippet(" ");
 currentlySelectedMarker.setTitle(" ");
 currentlySelectedMarker.showInfoWindow();

The call of setTitle is important. Otherwise showInfoWindow() will be ignored.