pks*_*pks 7 android android-maps
我试图在用户单击标记时从自定义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);
}
}
return v;
}
Run Code Online (Sandbox Code Playgroud)
我已经看过这些解决方案,但不明白究竟是什么能解决我的问题:
为什么自定义InfoWindow的谷歌地图v2,没有加载网址图片?
Gab*_*ira 28
您可以使用Picasso Callback onccess成功加载图像,如下所示
if (image != null) {
Picasso.with(getApplicationContext())
.load(image)
.placeholder(R.drawable.ic_launcher)
.into(i, new MarkerCallback(marker));
}
Run Code Online (Sandbox Code Playgroud)
并创建一个新类来处理Picasso Callback,就像这个MarkerCallback.java一样
public class MarkerCallback implements Callback {
Marker marker=null;
MarkerCallback(Marker marker) {
this.marker=marker;
}
@Override
public void onError() {
Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
}
@Override
public void onSuccess() {
if (marker != null && marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3739 次 |
| 最近记录: |