每次在每个标记上显示信息窗口 [英] show info window on every marker at a time

查看:95
本文介绍了每次在每个标记上显示信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示诸如

我可以在地图上显示所有标记,但我想显示信息窗口每当所有的标记都被填充时,每个标记都会被标记
我已经试过这个,但它显示了所有标记只有一个标记信息窗口。

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


推荐答案

无法显示一次有多个信息窗口。来自文档

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.

您可能需要查看 Google中的气泡图标映射Android API实用程序库
气泡图标为标记添加更强大的渲染选项,但不会改变它们的行为。这意味着您仍然无法一次显示多个信息窗口,但气泡图标可让您在每个标记上显示更多信息:

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:


添加一个IconGenerator以在
标记上显示信息摘要。此实用程序提供了一种使标记图标看起来像
有点像信息窗口的方法,因为标记本身可以包含文本
和其他内容。 优点是您可以同时打开多个
标记,而只有一个信息窗口可以一次打开
。您还可以对标记进行样式设置,更改
标记和/或内容的方向,并更改标记的背景
图像/九块补丁。

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.

更新:使用气泡图标的一个示例(考虑到您需要将Google Maps Android API实用程序库添加到您的项目之后这些说明):

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

这篇关于每次在每个标记上显示信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆