android百度地圖自定義marker,使用網絡圖片

由於提供的基礎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)));
                }
            });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章