Java 多个InfoWindows Android地图V2
因此,我的应用程序要求我为某辆公共汽车创建路线。我已经完成了这项工作,并为标记创建了一个自定义信息窗口。现在,我被要求添加一个功能,我需要在地图上显示标记周围的POI(兴趣点)。我已经成功地创建了这个。但是,我希望这些POI标记有一个不同的信息窗口 这是我的第一个信息窗口:Java 多个InfoWindows Android地图V2,java,android,google-maps,Java,Android,Google Maps,因此,我的应用程序要求我为某辆公共汽车创建路线。我已经完成了这项工作,并为标记创建了一个自定义信息窗口。现在,我被要求添加一个功能,我需要在地图上显示标记周围的POI(兴趣点)。我已经成功地创建了这个。但是,我希望这些POI标记有一个不同的信息窗口 这是我的第一个信息窗口: public class InfoAdapter implements GoogleMap.InfoWindowAdapter { LayoutInflater inflater = null; pr
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设置一个默认值):
这里是我称之为第一个的地方:
private void SetupStopMarkers(){
map.setInfoWindowAdapter(new InfoAdapter(getLayoutInflater()));
addMarkersToMap(markerPoints);
}
这里是我称之为第二个的地方:
else{
map.setInfoWindowAdapter(new PlacesAdapter(getLayoutInflater()));
...
}
我的信息布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:background="@drawable/businfo_dialog">
<ImageView
android:id="@+id/busicon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/busstop_icon"/>
<ImageView
android:id="@+id/clockicon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="@+id/busicon"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:src="@drawable/clock"
android:paddingBottom="10dp"/>
<TextView
android:id="@+id/businfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:drawablePadding="10dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/busicon"
android:layout_toEndOf="@+id/busicon"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/arrivalinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:drawablePadding="10dp"
android:layout_centerVertical="true"
android:layout_below="@+id/businfo"
android:layout_toRightOf="@+id/clockicon"
android:layout_toEndOf="@+id/clockicon"
android:paddingRight="10dp"
android:paddingTop="5dp"/>
<TextView
android:id="@+id/placesinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/arrivalinfo"
android:paddingTop="5dp"
android:paddingBottom="35dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#0099cc"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="@string/more_info"/>
<TextView
android:id="@+id/eta_i"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/arrivalinfo"
android:layout_toEndOf="@+id/arrivalinfo"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_alignTop="@+id/arrivalinfo"
android:text="ETA:"
android:textStyle="bold"
android:textColor="#FFFFFFFF"/>
</RelativeLayout>
但是在调用第二个信息窗口后,地图中的每个标记都会更改为第二个信息窗口。有办法做到这一点吗?感谢您的帮助。收到了。因此,要获得多个信息窗口,我必须获得与标记对应的标记ID。所以我创建了一个ArrayList,它接受标记的“id”
ArrayList<String> markerPlaces = new ArrayList<>();
然后在InfoAdapter上,我刚刚添加了一个条件,即如果标记id位于我创建的ArrayList中,则将其放入另一个充气器中
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);
}
}
谢谢大家的帮助!这确实让我思考 你能准确地分享你想要实现的目标吗?您不能设置多个InfoWindowAdapters,但您应该能够向现有InfoWindowAdapter添加功能,以实现所需的结果。感谢您的回复!我有两个不同的标记:位置标记和POI标记。我有一个用于a的自定义信息窗口,但我正在尝试为POI标记显示不同的信息窗口B。我认为最好的方法是根据标记的类型在信息窗口适配器中展开不同的布局。能否显示您的
InfoAdapter
和布局xml?InfoAdapter是上面的第一块代码。我刚刚上传了位置标记A的布局xml。POI标记B(目前)是默认的信息窗口。很好!这正是我所想的。
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());
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);
}
}