Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

android - show info window on every marker at a time

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();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...