【发布时间】:2018-06-02 08:25:08
【问题描述】:
我正在尝试制作带有一些标记的地图,它应该有一个带有图像和文本视图的信息标签。我已经解决了每个 infolabel 的文本都不同的问题,但我在 imageview 上苦苦挣扎。
当我添加新标记时,我的应用会获取新图像并将其放入存在的每个信息窗口中...
这是我的代码n-p,我在其中设置了图像和文本视图的值:
public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Activity context;
public CustomInfoWindowAdapter(Activity context){
this.context = context;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
boolean imageGeandert = false;
View view = context.getLayoutInflater().inflate(R.layout.custom_infowindow, null);
TextView tvTitle = (TextView) view.findViewById(R.id.nameTxt);
TextView tvSubTitle = (TextView) view.findViewById(R.id.addressTxt);
tvTitle.setText(marker.getTitle());
tvSubTitle.setText(marker.getSnippet());
ImageView imageView = (ImageView) view.findViewById(R.id.clientPic);
imageView.setImageResource(R.mipmap.logo);
Log.d("Loka2", String.valueOf(MapsActivity.iconFinalFinal2));
return view;
}
}
Log.d 输出如下所示:
*12-19 21:36:14.499 25315-25315/com.example.yannick.mapdemo D/Lokale 位图:android.graphics.Bitmap@9bb0b83
12-19 21:36:14.526 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@9bb0b83
12-19 21:36:14.672 25315-25315/com.example.yannick.mapdemo D/Lokale 位图:android.graphics.Bitmap@40daa30
12-19 21:36:14.682 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@40daa30
12-19 21:36:14.844 25315-25315/com.example.yannick.mapdemo D/Lokale 位图:android.graphics.Bitmap@4fa0090
12-19 21:36:14.854 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@4fa0090
12-19 21:36:14.948 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@4fa0090
12-19 21:36:15.014 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@4fa0090
12-19 21:36:15.062 25315-25315/com.example.yannick.mapdemo D/Loka2: android.graphics.Bitmap@4fa0090*
最后一个用于每个现有的信息窗口,我不知道为什么....
【问题讨论】:
-
您只需将每个 Marker 映射到一个图像 ID,并使用此映射来确定在
getInfoContents()中使用什么图像资源。你可以使用HashMap<Marker, Integer>。 -
感谢您的回答,您能给我一个简短的例子吗?
标签: android google-maps google-maps-markers google-maps-android-api-2 infowindow