-1

I want to display each marker title and snippet for all the markers in Google maps without clicking the marker, i.e it should display by default for all markers, something like this is trying to achieve?

How can I show label/title for marker permanently in Google Maps V3?

according to documentation there is an way showInfoWindow() but only displays for only one marker, how can i do this for all markers? or is there any other way to display marker information without clicking it?

Akash Jain
  • 684
  • 9
  • 23
  • generate a new instance of `infoWindow` for each marker you add - make sure that any events on the infowindow are prevented from closing the infowindow – Professor Abronsius Aug 22 '22 at 07:56
  • @ProfessorAbronsius how will i generate a instance of the `InfoWindow`? – Akash Jain Aug 22 '22 at 08:37
  • I have never written code in Android/Java so I am not sure. In Javascript you generate a new instance of an InfoWindow using `new google.maps.InfoWindow();` so I assume there is a similar method in Java – Professor Abronsius Aug 22 '22 at 08:42

1 Answers1

-1

For multiple markers with title write below code on onMapReady method of your activity.

Hope this helps...

       for (int i = 0; i < listOfMarkers.size(); i++) {
       LatLng latLng = new LatLng(listOfMarkers.get(i).latitude,listOfMarkers.get(i).longitude);

            Marker mk = googlemap.addMarker(new MarkerOptions()
                    .position(latLng)
                    .icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(listOfMarkers.get(i).getTitle());
          
        }
    }



 private Bitmap getMarkerBitmapFromView(String resId) {

    View customMarkerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_item_textview, null);
    TextView markerImageView = (TextView) customMarkerView.findViewById(R.id.tv_map_item_price);
    markerImageView.setText(resId);
    markerImageView.setTextColor(Color.parseColor("#000000"));
    customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
    customMarkerView.buildDrawingCache();
    Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
    Drawable drawable = customMarkerView.getBackground();
    if (drawable != null)
        drawable.draw(canvas);
    customMarkerView.draw(canvas);
    return returnedBitmap;
}
Android
  • 82
  • 1
  • 8