之前百度地图加载多个marker点的时候并没有发现这个问题,都是正常加载,今日使用高德地图发现一直显示占位图,我一直以为是glide加载的问题,于是乎我就给glide加了一个监听
RequestListener mRequestListener = new RequestListener() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
Log.d("fhxx", "onException: " + e.toString() + " model:" + model + " isFirstResource: " + isFirstResource);
return false;
}
@Override
public boolean onResourceReady(Object resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
Log.e("fhxx", "model:" + model + " isFirstResource: " + isFirstResource);
return false;
}
};
Glide.with(MemberPositionActivity.this)
.load(data.get(i).getHeadimg())
// .load("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png")
.listener(mRequestListener )
// .apply(RequestOptions.bitmapTransform(new CircleCrop()))
// .placeholder(R.mipmap.icon_header_zhanwei)
// .dontAnimate()
.into(image_header);
返回的log都是走的成功,并且打印出已经加载。
这个时候,我想到是不是是别的原因,有没有可能是高德地图的问题?于是乎我抱着试一试的态度来修改了一下。
修改前:for循环设置marker点位信息,但是不显示图片
for (int i = 0; i < data.size(); i++) {
String[] split = data.get(i).getGps().split(",");
View inflate = LayoutInflater.from(MemberPositionActivity.this).inflate(R.layout.marker, null);
ImageView image_header = inflate.findViewById(R.id.image_header);
Glide.with(MemberPositionActivity.this)
.load(data.get(i).getHeadimg())
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.placeholder(R.mipmap.icon_header_zhanwei)
.into(image_header);
MarkerOptions markerOption = new MarkerOptions();
markerOption.position(new LatLng(Double.valueOf(split[1]), Double.valueOf(split[0])));
markerOption.title(data.get(i).getName());
markerOption.draggable(false);//设置Marker可拖动
markerOption.icon(BitmapDescriptorFactory.fromBitmap(convertViewToBitmap(inflate)));
// 将Marker设置为贴地显示,可以双指下拉地图查看效果
markerOption.setFlat(false);//设置marker平贴地图效果
objects1.add(markerOption);
aMap.addMarker(markerOption);
}
?
修改后:
for (int i = 0; i < data.size(); i++) {
String[] split = data.get(i).getGps().split(",");
View inflate = LayoutInflater.from(MemberPositionActivity.this).inflate(R.layout.marker, null);
ImageView image_header = inflate.findViewById(R.id.image_header);
int finalI = i;
Glide.with(MemberPositionActivity.this)
.load(data.get(i).getHeadimg())
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.placeholder(R.mipmap.icon_header_zhanwei)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
image_header.setImageDrawable(resource);
// textView.setText(list.get(I).getGasName() + "");
Bitmap bitmap = convertViewToBitmap(inflate);
MarkerOptions markerOption = new MarkerOptions();
markerOption.position(new LatLng(Double.valueOf(split[1]), Double.valueOf(split[0])));
markerOption.title(data.get(finalI).getName());
markerOption.draggable(false);//设置Marker可拖动
markerOption.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
aMap.addMarker(markerOption);
}
});
}
?
测试,可以正常显示
|