多个InfoWindows Android Maps V2

所以我的应用程序要求我为某辆公共汽车创建一条路线。 我已完成此操作并为标记创建了自定义信息窗口。 现在,我被要求添加一个function,我需要在地图上显示标记周围的POI(兴趣点)。 我已成功创建了这个。 但是,我想为这些POI标记设置不同的信息窗口。

这是我的第一个信息窗口:

public class InfoAdapter implements GoogleMap.InfoWindowAdapter { LayoutInflater inflater = null; private TextView textViewstopName; private TextView arrivalTime; public InfoAdapter(LayoutInflater inflater) { this.inflater = inflater; } @Override public View getInfoWindow(Marker marker) { View v = inflater.inflate(R.layout.businfo_layout, null); if (marker != null) { textViewstopName = (TextView) v.findViewById(R.id.businfo); textViewstopName.setText(marker.getTitle()); arrivalTime = (TextView) v.findViewById(R.id.arrivalinfo); arrivalTime.setText(marker.getSnippet()); } return (v); } @Override public View getInfoContents(Marker marker) { return (null); } } 

这是我的第二个(我现在要为POI默认一个):

  public class PlacesAdapter implements GoogleMap.InfoWindowAdapter{ LayoutInflater inflater = null; public PlacesAdapter(LayoutInflater inflater) { this.inflater = inflater; } @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { return null; } } 

这是我称之为第一个:

  private void SetupStopMarkers(){ map.setInfoWindowAdapter(new InfoAdapter(getLayoutInflater())); addMarkersToMap(markerPoints); } 

这是我称之为第二个:

 else{ map.setInfoWindowAdapter(new PlacesAdapter(getLayoutInflater())); ... } 

我的info_layout:

          

但在调用第二个信息窗口后,地图中的每个标记都会更改为该第二个信息窗口。 有没有办法做到这一点? 任何帮助表示赞赏。

得到它了。 因此,为了获得多个Info窗口,我必须获得与标记相对应的标记ID。 所以我创建了一个ArrayList,它接收标记的“id”。

  ArrayList markerPlaces = new ArrayList<>(); 

然后,当我将标记添加到地图时,我填充它:

  Marker marker = map.addMarker(new MarkerOptions().position(position) .title(venuesfound.get(i).getName()) .snippet("\nOpen: " + venuesfound.get(i).getOpenNow() + "\n(" + venuesfound.get(i).getCategory() + ")") .icon(BitmapDescriptorFactory.fromResource(R.drawable.measle_blue))); markerPlaces.add(marker.getId()); 

然后在InfoAdapter上,我添加了一个条件,如果标记id在我创建的ArrayList中,则放入另一个inflater。

  public class InfoAdapter implements GoogleMap.InfoWindowAdapter { LayoutInflater inflater = null; private TextView textViewstopName; private TextView arrivalTime; public InfoAdapter(LayoutInflater inflater) { this.inflater = inflater; } @Override public View getInfoWindow(Marker marker) { if (marker != null) { if(markerPlaces.containsKey(marker.getId())) { ... //Add new inflater here. } //checks if the marker is part of the Position marker or POI marker. else{ View v = inflater.inflate(R.layout.businfo_layout, null); textViewstopName = (TextView) v.findViewById(R.id.businfo); textViewstopName.setText(marker.getTitle()); arrivalTime = (TextView) v.findViewById(R.id.arrivalinfo); arrivalTime.setText(marker.getSnippet()); return (v); } } return null; } @Override public View getInfoContents(Marker marker) { return (null); } } 

谢谢大家的帮助! 这当然让我思考!