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:

  1. replace web image local image, problem still occur.
  2. store marker arraylist, after process completed, set markers showinfowindow() , set markers hideinfowindow(). works, there infowindow cannot closed(the final one).
  3. 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:

https://lh4.googleusercontent.com/......

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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -