androidgoogle-mapsgoogle-maps-api-2

Hide InfoWindow from GoogleMaps API but keep the directions icon


I am trying to use the GoogleMap API on android, but I want to hide the infoWindow when a user clicks on a pin that dropped. Yet, I still want the directions and latlog icon to show up.

In other words, the picture should clarify what I need:

enter image description here

I tried to add a listener to the pins I dropped, but this kills the entire infoWindow and the directions icons as well, as such:

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    LatLng location1 = new LatLng(32.75613, -117.11648);
    mMap.addMarker(new MarkerOptions().position(location1).title("Hello"));

    LatLng location2 = new LatLng(32.754978528015876, -117.12977170944214);
    mMap.addMarker(new MarkerOptions().position(location2).title("World"));

    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location1, 12.0f)); //zoom out

    // This does not work, if I turn it to true, I loose the directions icon
    // I don't want a custom info window, I just want to hide it and have the directions
    // icon still showing up
    if (false) {
        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker) {
                Log.d("zzz", "marker = " + marker.getTitle());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 14.0f)); //zoom out
                return true;
            }
        });
    }
}

Is it possible to do, without re-writing the entire logic of the directions icon?

thx!


Solution

  • better solution, just made the achor point way off the screen.

    private static final float ACHOR_WINDOWS_U = -9999;
    private static final float ACHOR_WINDOWS_V = -9999;
    

    ...

    Marker marker = map.addMarker(markerOptions);
    marker.setInfoWindowAnchor(ACHOR_WINDOWS_U, ACHOR_WINDOWS_V);