【发布时间】:2015-07-23 02:20:16
【问题描述】:
我的 android 使用 Google map android API,InfoWindow 的图像在第一次点击时不显示,但在第二次点击时可以工作
我使用
自定义 infoWindowvoid setMapInfoWindow(){
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.windowlayout, null);
final ImageView img = (ImageView)v.findViewById(R.id.imageView3);
//image
Picasso.with(context).load("http://imgurl").resize(140,
}
});
}
这是我的标记设置过程
void setMarkers(){
...
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject datas=jsonArray.getJSONObject(i);
MarkerOptions tmp=new MarkerOptions()
.title("name")
.alpha(0.6f)
.position(new LatLng(123,456));//replace LatLng with sample
marker=mMap.addMarker(tmp);
}
....
setMapInfoWindow();
}
完成Marker的设置后,调用setMapInfoWindow()函数。
它可以在我的智能手机上使用,但是当您第一次单击 infoWindow 时,它不会显示图像;但它会在第二次点击时显示。
我测试了一些情况:
- 将网页图片替换为本地图片,问题依旧。
- 将所有标记存储到ArrayList中,所有过程完成后,将所有标记设置为
showInfoWindow(),然后将所有标记设置为hideInfoWindow()。它可以工作,但是有一个 infoWindow 无法关闭(最后一个)。 - 我正在尝试使用位图来获取图像,但它没有显示图像,我尝试了很多来自 stackoverflow 的方法。但在使用 Picasso 库时它可以工作。
谢谢
通过以下方式解决的问题: 加载时似乎 google 网络服务的图像 URL 将更改为另一个 URL。
示例:
https://maps.googleapis.com/maps/api/place/photo?photoreference=
它会被谷歌更改为以下网址:
所以我将布尔 not_first_time_showing_info_window 更改为 int,并回调 3 次
int not_first_time_showing_info_window=0;
//show image
try {
if(not_first_time_showing_info_window==2){
not_first_time_showing_info_window=0;
Picasso.with(HomeActivity.this).load("http://....").resize(600,400).into(img);
}
else if (not_first_time_showing_info_window==1) {
not_first_time_showing_info_window++;
Picasso.with(HomeActivity.this).load("http://....").resize(600, 400).into(img,new InfoWindowRefresher(marker));
}else if(not_first_time_showing_info_window==0){
not_first_time_showing_info_window++;
Picasso.with(HomeActivity.this).load("http://....").resize(600,400).into(img,new InfoWindowRefresher(marker));
}
} catch (Exception e) {
img.setImageDrawable(null);
}
【问题讨论】:
-
所以如果你使用毕加索图书馆,第一次点击就会显示图像,对吧?
-
不,第二次点击会显示使用毕加索库
-
我通过 [this solution][1] 解决了这个问题,谢谢。 [1]:stackoverflow.com/a/22009558/2971851
标签: android google-maps google-maps-markers infowindow