我正在使用谷歌地图Api,并希望在点击标记时在InfoWindow中显示图像.我实现了它,但毕加索有一个问题.单击标记时,将显示infoWindow,imageView将显示占位符图像.如果我再次单击相同的标记,Picasso会成功加载图像.我必须点击两次,这太奇怪了.
屏幕截图以便更好地理解:
首先点击标记:
当我再次点击时:
我的代码如下:
InfoWindowAdapter(毕加索在这里加载)
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View myContentsView = getLayoutInflater().inflate(R.layout.map_info_content, null);
ImageView imageView = (ImageView) myContentsView.findViewById(R.id.imgView_map_info_content);
Picasso.with(MainActivity.this)
.load(marker.getSnippet())
.placeholder(R.drawable.ic_placeholder)
.into(imageView);
return myContentsView;
}
});
Run Code Online (Sandbox Code Playgroud)
设置标记(使用代码段传递图像网址)
for (MediaFeedData item : mItemList) {
LatLng position = new LatLng(item.getLocation().getLatitude(),
item.getLocation().getLongitude());
mMap.addMarker(new MarkerOptions()
.snippet(item.getImages().getLowResolution().getImageUrl())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_point))
.position(position));
}
Run Code Online (Sandbox Code Playgroud)
InfoWindow布局xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imgView_map_info_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android google-maps-markers google-maps-android-api-2 picasso
我试图在用户单击标记时从自定义infoWindow中的URL加载图像.我能够加载其他细节,但图像没有加载它.我正在使用Picasso库为我这样做.我搜索了许多相关主题并查看了解决方案,但无法理解应用哪种解决方案来解决我的问题.我正在使用Web服务调用来获取所需的数据.
这是我的代码:
@Override
public View getInfoContents(Marker arg0) {
//marker.showInfoWindow();
return null;
}
@Override
public View getInfoWindow(Marker arg0)
{
View v = getLayoutInflater().inflate(R.layout.map_infowindow, null);
for(int i=0 ; i<lstMain.size();i++)
{
Pojo b=lstMain.get(i);
double slat= Double.parseDouble(b.getLatitude());
double slng= Double.parseDouble(b.getLongitude());
double lat= Math.round(slat*100000.0)/100000.0;
double lng= Math.round(slng*100000.0)/100000.0;
String s1=String.valueOf(lat);
String s2=String.valueOf(lng);
Log.v("comparing latilongi pojo===>", lat+" , "+lng);
Log.v("comparing latilongi marker===>", Clickedlatitude+" , "+Clickedlongitude);
if(s1.equals(String.valueOf(Clickedlatitude)) && s2.equals(String.valueOf(Clickedlongitude)))
{
txtDname=(TextView)v.findViewById(R.id.infoDoctorName);
txtDspe=(TextView)v.findViewById(R.id.infoDoctorSpe);
txtDaddress=(TextView)v.findViewById(R.id.infoDoctorAddress);
imgUrl=(ImageView)v.findViewById(R.id.infoDoctorImage);
String url=b.getPhotoURL();
txtDname.setText(b.getDoctorName());
txtDspe.setText(b.getSpecialization());
txtDaddress.setText(b.getAddress1()+" , "+b.getAddress2());
Picasso.with(MapActivity.this)
.load(url)
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher).resize(50, 50)
.into(imgUrl);
} …Run Code Online (Sandbox Code Playgroud) 我试图在Google Maps Marker的InfoWindow中设置一个ImageView,并且已经完全复制了这个答案中的代码,除了我的InfoWindowAdapter不是一个匿名内部类(它只是活动的内部类).这之前有效,但由于某种原因它已停止工作 - 回调中的onSuccess方法没有被调用,因此InfoWindow仅在第二次打开时显示图像.
看看毕加索的日志,我收到类似的消息Main canceled [R20]+374ms target got garbage collected.我想这可能是因为Callback正在获取gc'd,并尝试将其设置为final,并且还将对象保存在类字段中(这些都不起作用,尽管我可能做错了吗?)
可能会发生什么,我该如何解决?是target在引用回调的错误消息中,还是它可以引用作为参数传递给Callback的构造函数的标记?
另一件奇怪的事情是,有时在InfoWindow首次打开时图像被正确加载 - 我正在试图找出原因,但基本上我有很多标记,并且他们的图像是否正确加载或者首先加载似乎是不一致.首次打开InfoWindow时,有些(大多数)似乎永远无法正确加载.
[编辑]这是在一堆代码合并到该活动之后,它可能是一个记忆的东西吗?(现在处理的时间比我没有遇到这个问题时要多)
[编辑2]我和Glide有完全相同的问题!可能垃圾收集?