由于提供的基础marker只提供icon,所以如果marker需要显示更多信息,就需要自定义View
使用网络图片标记marker,需要等图片加载完毕再添加marker
for (GridPoint gridPoint : pointList) {
//这个是自定义marker 视图,和普通视图一样
View inflate = LayoutInflater.from(MapGridActivity.this).inflate(R.layout.map_point_marker, null);
ImageView imageView = inflate.findViewById(R.id.iv_point);
TextView textView = inflate.findViewById(R.id.tv_point);
Glide.with(MapGridActivity.this)
.asBitmap()
.load(Constant.FILE_URL+gridPoint.getMapPointType().getShowImage())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
LatLng point = new LatLng(gridPoint.getLat(), gridPoint.getLon());
imageView.setImageBitmap(resource);
textView.setText(gridPoint.getName());
baiduMap.addOverlay(new MarkerOptions()
.position(point)
.icon(BitmapDescriptorFactory.fromView(inflate)));
}
});