我正在使用Android应用程序.用户在谷歌地图上搜索餐馆.在谷歌地图显示所有邻居的餐厅标记.如果他点击标记,它会显示自定义InfoWindow.我的问题是我无法加载返回谷歌的图像.我正确的图像的网址,但我不能在窗口显示它.
信息窗口
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/bg_color" >
<ImageView
android:id="@+id/place_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"" />
<TextView
android:id="@+id/place_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/place_vicinity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/bg_color" >
<RatingBar
android:id="@+id/place_rating"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:rating="0"
android:isIndicator="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip" />
<ImageView
android:id="@+id/navigate_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:src="@drawable/navigate" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在创造我有这个
mGoogleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View …Run Code Online (Sandbox Code Playgroud) 我创建了一个实现MapsView的应用程序.当我点击标记时,它将显示信息窗口,其中使用picasso从数据库中检索数据.它工作正常,但问题是信息窗口中的图像没有显示我需要的图像,它仍然显示占位符图像.但是当我点击地图并再次点击标记时,它会显示我需要的图像.但如果我没有点击地图(仍然点击标记),它仍然总是显示占位符标记.如何用时间显示我需要的图像(占位符图像将替换为我需要的图像)?
这是我的代码
public void plotMarkers(ArrayList<MyMarker> markers) {
if(markers.size() > 0) {
for (MyMarker myMarker : markers)
{
dest = new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude());
markerOption = new MarkerOptions().position(dest);
location_marker = mMap.addMarker(markerOption);
Target target = new PicassoMarker(location_marker);
targets.add(target);
ImageView image = new ImageView(this);
image.setImageResource(R.mipmap.marker);
int width = image.getDrawable().getIntrinsicWidth();
int height = image.getDrawable().getIntrinsicHeight();
Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(width, height).onlyScaleDown().into(target);
mMarkersHashMap.put(location_marker, myMarker);
i = getIntent();
if(i.getBooleanExtra("maps", true)) {
location_marker.setTitle(i.getStringExtra("nama"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(dest, 16));
}
else {
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
}
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
@Override
public View …Run Code Online (Sandbox Code Playgroud) 我尝试将带有Picasso的Firebase存储中的图像加载到一个Imageview中,该Imageview放置在Marker的InfoWindowAdapter中.
我非常绝望.问题是Picasso只显示占位符Icon.
我的代码FirebaseStorageRefernce看起来像这个引用此Firebase博客文章:
StorageReference load = getImage(id);
load.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
downloadUri = uri;
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Failure",e.toString());
}
});
Run Code Online (Sandbox Code Playgroud)
我得到的downloadUri是有效的,工作正常.现在我使用这个下载Uri for Picasso.
Picasso picasso = new Picasso.Builder(getApplicationContext()).listener(new Picasso.Listener() {
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
e.printStackTrace();
}
}).build();
picasso.setLoggingEnabled(true);
picasso.load(downloadUri).placeholder(R.drawable.toxic_bait_icon).fit().into(thump, new MarkerCallback(marker));
Run Code Online (Sandbox Code Playgroud)
参考我在StackOverFlow上找到的答案,我做了一个MarkerCallback类:
public class MarkerCallback implements Callback {
com.google.android.gms.maps.model.Marker marker = null;
MarkerCallback(Marker marker)
{ …Run Code Online (Sandbox Code Playgroud)
我正在使用Google maps APIv2 for android.我已经实现了MapFragment,将标记放在我需要的位置,为标记添加了自定义InfoWindow.
问题是 - 我在InfoWindow中有AsyncImages,并在那里有ProgressBar.问题是 - ProgressBar没有旋转,Image从缓存中获取后没有设置.AsyncImages运行良好.我已将它测试到另一个类.
我只用一个ProgressBar替换了我的AsyncImages视图- 相同.它不旋转.
有什么建议?
旋转器不会旋转原因
注意:绘制的信息窗口不是实时视图.视图在返回时呈现为图像(使用View.draw(Canvas)).这意味着对视图的任何后续更改都不会被地图上的信息窗口反映出来.要稍后更新信息窗口(例如,在加载图像之后),请调用showInfoWindow().此外,信息窗口将不会考虑正常视图(例如触摸或手势事件)的任何典型交互.但是,您可以在整个信息窗口中收听通用点击事件,如下节所述.
所以问题是 - 如何以最佳方式从地图上的网络/缓存实现AsyncImages?
在getContentInfo()方法的某个地方创建Views数组,并像OnImageDownloaded一样创建监听器smth ?
android android-imageview progress-bar google-maps-android-api-2