gmmo
gmmo

Reputation: 2801

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!

Upvotes: 1

Views: 879

Answers (3)

Stephan Venter
Stephan Venter

Reputation: 338

The easiest solution seems not to define the Title when creating the new MarkerOptions when adding the Marker.

So for example:

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

Note that I have not defined the Title as "Hello" as shown in your example.

Upvotes: 0

gmmo
gmmo

Reputation: 2801

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);

Upvotes: 3

blackkara
blackkara

Reputation: 5052

try this

map.addMarker(new MarkerOptions().position(new LatLng(0, 0)));    
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 14.0f));
        return false;
    }
});

Upvotes: 0

Related Questions