show info window on every marker at a time
Asked Answered
M

1

28

I want to show something like this

I am able to show all the markers on the map but I want to show info window on every markers whenever all the markers are populated. I've tried this so far but it shows all the markers with only one markers info window.

for (int i = 0; i < jobsDtoList.size(); i++) {
    Double latitude = Double.parseDouble(jobsDtoList.get(i).getSiteLatitude());
    Double longitude = Double.parseDouble(jobsDtoList.get(i).getSiteLongitude());

    LatLng latLng = new LatLng(latitude, longitude);
    MarkerOptions TP = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.mipmap.job_marker));
    googleMap.addMarker(TP).showInfoWindow();
}
Miscalculate answered 7/10, 2015 at 5:0 Comment(0)
S
26

It is not possible to show more than one info window at a time. From the documentation:

An info window allows you to display information to the user when they tap on a marker. Only one info window is displayed at a time. If a user clicks on another marker, the current info window will be hidden and the new info window will be displayed.

You may want to take a look at bubble icons from the Google Maps Android API Utility Library. Bubble icons adds more powerful rendering options for the markers, but does not change their behaviour. It means that you still won't be able to show more than one info window at a time, but bubble icons will allow you to show more info on each marker:

Add a IconGenerator to display snippets of information on your markers. This utility provides a way of making your marker icons look a bit like info windows, in that the marker itself can contain text and other content. The advantage is that you can keep more than one marker open at the same time, whereas only one info window can be open at once. You can also style the markers, change the orientation of the marker and/or content, and change the marker's background image/nine-patch.

UPDATE: An example using bubble icons (take into account that you will need to add the Google Maps Android API utility library to your project following this instructions):

LatLng latLng = new LatLng(latitude, longitude);

TextView text = new TextView(context);
text.setText("Your text here");
IconGenerator generator = new IconGenerator(context);
generator.setBackground(context.getDrawable(R.drawable.bubble_mask));
generator.setContentView(text);
Bitmap icon = generator.makeIcon();

MarkerOptions tp = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(icon));
googleMap.addMarker(tp);
Stria answered 7/10, 2015 at 8:1 Comment(4)
so is there way to add custom marker with the textfield to display all titles on all markers besides infowindow ?Miscalculate
@Ram Mandal I have updated my answer with an exampleStria
Thanks for the suggestion bro. really appreciate your helpMiscalculate
well, I ve markers on map and I want to show IconGenerator as a infoWindow. but if I do that way. my markers and IconGenerator's text over and over. how can add a offset for this IconGeneratorLeavelle

© 2022 - 2024 — McMap. All rights reserved.