问题描述
如何在Android Maps V2上隐藏多个标记?
How can I hide multiple markers on Android Maps V2?
我有10个标记. 5个特定类型的电影院和5个其他类型的电影院.
I have 10 markers. 5 a certain type of cinema and 5 another type.
如果我使用以下代码,则最后一个标记消失.
If I use the below code only the last marker disappears.
marker Cinema1,cinema2;
Marker cinema1,cinema2;
cinema1 = gMap.addMarker ......
cinema1 = gMap.addMarker......
cinema1 = gMap.addMarker ......
cinema1 = gMap.addMarker......
cinema2 = gMap.addMarker ......
cinema2 = gMap.addMarker......
cinema2 = gMap.addMarker ......
cinema2 = gMap.addMarker......
以此类推
点击事件
cinema1.setVisible(false);
cinema1.setVisible(false);
这只会将最后一个= = Cinema1的标记设置为不可见(很明显),所以问题是如何在不声明每个标记的情况下将所有5个标记设置为不可见?
This only sets the last marker = to cinema1 to invisible (obviously) so the questions is how can I set all 5 markers invisible without declaring a Marker for each?
谢谢
推荐答案
您应创建带有标记的列表并在其帮助下进行操作.
You should create list with markers and manipulate with its help.
Marker dilers1,dilers2;
List<Marker> markers = new ArrayList<>();
dilers1 = mMap.addMarker(new MarkerOptions().position(new LatLng(55.755823,37.622315)).title("Melbourne"));
dilers2 = mMap.addMarker(new MarkerOptions().position(new LatLng(55.765823,37.612315)).title("Melbourne2"));
markers.add(dilers1);
markers.add(dilers2);
public void changer(){
for (Marker mkr: markers) {
mkr.setVisible(false);
}
}
这篇关于Android地图将多个标记设置为不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!