Search code examples
androidandroid-fragmentsandroid-mapviewandroid-maps-v2android-maps

set onMarkerClickListener along with title, but either one of them shows up. How to show both?


I'm using this line to generate a title for the marker-

mMap.addMarker(new MarkerOptions().position(latLng).title("Last location"));

Then if I set onMarkerClickListener

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            Toast.makeText(MapsActivity.this, "Clicked on marker", Toast.LENGTH_SHORT).show();
            return true;
        }

Marker title wouldn't show. I need to show both, toast and marker title; how to do that, if it is possible?


Solution

  • Add a line marker.showInfoWindow(); inside the onMarkerClick method.