android - infoWindow's image now showing on first click, but it works on second click -
my android using google map android api,infowindow's image not showing on first click, works on second click
i customize 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 marker set process
void setmarkers(){ ... (int = 0; < jsonarray.length(); i++) { jsonobject datas=jsonarray.getjsonobject(i); markeroptions tmp=new markeroptions() .title("name") .alpha(0.6f) .position(new latlng(123,456));//replace latlng sample marker=mmap.addmarker(tmp); } .... setmapinfowindow(); }
after complete marker's setting, call setmapinfowindow()
function.
it work on smartphone, when click infowindow on first time, not show image ; showing when second click.
i test cases:
- replace web image local image, problem still occur.
- store marker arraylist, after process completed, set markers
showinfowindow()
, set markershideinfowindow()
. works, there infowindow cannot closed(the final one). - i'm trying use bitmap image, not showing image, trying lot of ways stackoverflow. work when using picasso library.
thanks
the problem solved by: seems google web service's image url changed url when loading.
example:
https://maps.googleapis.com/maps/api/place/photo?photoreference=
it changed following url google:
so change boolean not_first_time_showing_info_window int,and callback 3 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); }
first can make custom callback class implement com.squareup.picasso.callback
:
private class infowindowrefresher implements callback { private marker markertorefresh; private infowindowrefresher(marker markertorefresh) { this.markertorefresh = markertorefresh; } @override public void onsuccess() { markertorefresh.showinfowindow(); } @override public void onerror() {} }
second, declare boolean variable in activity:
boolean not_first_time_showing_info_window;
third, implement public view getinfocontents(marker marker)
method:
@override public view getinfocontents(marker marker) { view v = getlayoutinflater().inflate(r.layout.custom_window, null); imageview image = (imageview)v.findviewbyid(r.id.image_view); if (not_first_time_showing_info_window) { picasso.with(mainactivity.this).load("image_url.png").into(image); } else { not_first_time_showing_info_window = true; picasso.with(mainactivity.this).load("image_url.png").into(image, new infowindowrefresher(marker)); } return v; }
you can visit this github page completed implementation.
Comments
Post a Comment