一次显示每个标记的信息 window

show info window on every marker at a time

我想展示类似

的内容

我能够在地图上显示所有标记,但我想在填充所有标记时在每个标记上显示信息 window。 到目前为止我已经试过了,但它显示所有标记只有一个标记信息 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();
}

一次不能显示多个信息 window。来自 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.

您可能想看看 Google Maps Android API Utility Library 中的气泡图标。 气泡图标为标记添加了更强大的渲染选项,但不会改变它们的行为。这意味着您仍然无法一次显示多个信息 window,但气泡图标可让您在每个标记上显示更多信息:

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.

更新:使用气泡图标的示例(考虑到您需要在 this instructions 之后将 Google 地图 Android API 实用程序库添加到您的项目中):

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