Search code examples
javaandroidgoogle-maps-markersgoogle-maps-api-2

GoogleMaps V2 - Show full snippet of marker


I'm displaying a GoogleMap v2 with plenty of Marker's with their own customized .snippet() layout.

When clicking on a Marker, the map will move itself so the Marker is centered. The snippet will pop up and show itself above the Marker. Now my problem is that the snippet is bigger (higher) than there is space above the Marker!

How can I make the snippet beeing viewed in full size? I want everything of the snippet to be shown, so I don't have to scroll up to read the upper part of the content!

Thanks


Solution

  • You can use the GoogleMap.InfoWindowAdapter to replace the native layout with a custom one.

    You would have something like this:

     private GoogleMap mMap;
     mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
    
            @Override
            public View getInfoWindow(Marker arg0) {
                 
                 View v = getLayoutInflater().inflate(R.layout.your_custom_layout, null);
                 return v;
    
            }
    
            @Override
            public View getInfoContents(Marker arg0) {
    
                 return null;    
            }
        });
    

    Now you can alter the size / look of the info window through your own layout.

    • The getInfoWindow() will replace the info window frame.
    • The getInfoContents() will replace the content of the info window by using the standard frame. It will fire only if getInfoWindow() returns null.

    But AFAIK this is limited. You can't add Views, which response to click listeners f.e.