gpt4 book ai didi

android - 图片未加载到 Google map 标记中

转载 作者:行者123 更新时间:2023-11-29 01:05:53 27 4
gpt4 key购买 nike

我正在尝试在 Google map 中加载我在标记窗口中从 Firebase 存储中获取的图像。问题是,当我尝试使用 Glide 或 Picasso 加载它时,它没有加载到 Google map 中。我在代码中的每个日志都在 logcat 中可见。我在这里做错了什么吗?

这是我的代码

public class MapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

Context context;
LayoutInflater inflater;
private DatabaseReference mDatabase;
private StorageReference storageReference;
private Chalet chalet;
private boolean query;
private ImageView img;
private String lat;
private String log;

public MapInfoWindowAdapter(Context context, LayoutInflater inflater) {
this.context = context;
this.inflater = inflater;
}

@Override
public View getInfoWindow(Marker marker) {
return null;
}

@Override
public View getInfoContents(final Marker marker) {

mDatabase = FirebaseDatabase.getInstance().getReference().child("chalets");
storageReference=FirebaseStorage.getInstance().getReference();

inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = inflater.inflate(R.layout.marker_tag,null);

final LatLng latlng = marker.getPosition();
Double doubleLat = latlng.latitude;

lat = String.valueOf(latlng.latitude);
log = String.valueOf(latlng.longitude);
Log.i("MarkerPostion",lat);

img = (ImageView) v.findViewById(R.id.chaletImg);

// final TextView textView = (TextView) v.findViewById(R.id.markerText);
final Semaphore semaphore = new Semaphore(0);
mDatabase.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {

Log.i("MarkerPostion","112211");
for (DataSnapshot snapm: dataSnapshot.getChildren()) {
Log.i("MarkerPostion",snapm.child("latitude").getValue().toString());
Log.i("Key",snapm.getKey());
if ( lat.equals(snapm.child("latitude").getValue().toString()) && log.equals(snapm.child("longitude").getValue().toString()) ){
chalet = snapm.getValue(Chalet.class);
Log.i("MarkerPostion","9999");
break;
}
}

storageReference = FirebaseStorage.getInstance().getReference().child(chalet.getOwnerID()).child(chalet.getChaletNm()).child("1");
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {

@Override
public void onSuccess(Uri uri) {
Picasso.with(context).load(uri).into(img);
Log.i("MarkerPostion","2222");
}
});
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

return v;
}
}

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/markerFrame">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/chaletImg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>

</LinearLayout>

</FrameLayout>

最佳答案

问题是 map 标记呈现为位图而不是实时 View ,这意味着当 Picasso 完成加载图像时,您的标记已经呈现,您需要刷新它以显示更改。

您需要做的是在 Picasso 或 Glide 调用上实现回调,并在加载图像后调用 marker.showInfoWindow()

编辑:我认为这是您唯一需要的更改:

Picasso.with(context).load(uri).into(img, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {
marker.showInfoWindow()
}

@Override
public void onError() {

}
});

您还可以在调用 marker.showInfoWindow() 之前检查 if (marker != null && marker.isInfoWindowShown())...

关于android - 图片未加载到 Google map 标记中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47287427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com