My android using the Google map android API,InfoWindow's image not showing on first click, but it works on second click
I customize the infoWindow using
void 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,
}
});
}
Here is my marker set up process
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();
}
After I complete the Marker's setting, I call the setMapInfoWindow()
function.
It work on my smartphone, but when you click the infoWindow on first time, It would not show the image ; but it showing when second click.
I test for some cases:
- replace the web image to local image, the problem still occur.
- store all marker into ArrayList, after all process completed, set all markers to
showInfoWindow()
, then set all markers to hideInfoWindow()
. It works, but there are a infoWindow cannot be closed(the final one).
- I'm trying use the Bitmap to get the image, But It not showing image, I trying a lot of ways from stackoverflow. But it work when using the Picasso library.
Thanks
the problem solved by:
it seems the google web service's image URL will be changed to another URL when loading.
example:
https://maps.googleapis.com/maps/api/place/photo?photoreference=
it will be changed to following URL by google:
https://lh4.googleusercontent.com/......
so I change the boolean not_first_time_showing_info_window to int,and callback three times
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);
}
See Question&Answers more detail:
os