Display toolbar for Google Maps marker automatically Display toolbar for Google Maps marker automatically android android

Display toolbar for Google Maps marker automatically


The overlay that appears when a marker is clicked, is created and destroyed on-the-spot implicitly. You can't manually show that (yet).

If you must have this functionality, you can create an overlay over your map with 2 ImageViews, and call appropriate intents when they're clicked:

// DirectionsIntent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(        "http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15"));startActivity(intent);// Default google mapIntent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(        "http://maps.google.com/maps?q=loc:51.5, 0.125"));startActivity(intent);

Note: you need to change the coordinates based on Marker's getPosition() and the user's location.

Now to hide the default overlay, all you need to do is return true in the OnMarkerClickListener. Although you'll lose the ability to show InfoWindows and center camera on the marker, you can imitate that simply enough:

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {    @Override    public boolean onMarkerClick(Marker marker) {        marker.showInfoWindow();        mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));        return true;    }});


Quoting the doc:

In a lite-mode map, the toolbar persists independently of the user's actions. In a fully-interactive map, the toolbar slides in when the user taps a marker and slides out again when the marker is no longer in focus.

Seeems like there is no way to persist the toolbar in your case since its an interactive map. You might want to try using lite-mode if that is a requirement: https://developers.google.com/maps/documentation/android/lite

Also looking at your code:

// create markerMarkerOptions marker = new MarkerOptions().position(        new LatLng(latitude, longitude)).title("title");// adding markergoogleMap.addMarker(marker).showInfoWindow();googleMap.getUiSettings().setMapToolbarEnabled(true);

The very last line: googleMap.getUiSettings().setMapToolbarEnabled(true); is redundant unless you are explicitly setting it to false beforehand. The doc states:

Sets the preference for whether the Map Toolbar should be enabled or disabled. If enabled, users will see a bar with various context-dependent actions, including 'open this map in the Google Maps app' and 'find directions to the highlighted marker in the Google Maps app'.

By default, the Map Toolbar is enabled.

The link: https://developer.android.com/reference/com/google/android/gms/maps/UiSettings.html#setMapToolbarEnabled(boolean)

Hope this helps.