how to add different images in different information window for different markers in google maps api v2 for android -


i have made lot of markers want each information window of marker must unique have written xml information window not working accordingly every time single image shows up.

// setting custom info window adapter google map mymap.setinfowindowadapter(new infowindowadapter() {      // use default infowindow frame      public view getinfowindow(marker arg0) {         return null;     }      // defines contents of infowindow      public view getinfocontents(marker marker) {          // getting view layout file info_window_layout         view v = getlayoutinflater().inflate(                 r.layout.info_window_layout, null);          // getting position marker         latlng latlng = marker.getposition();         double latitude=latlng.latitude;         double langitude=latlng.longitude;          string lat = string.format("%.6f", latitude);         string lng = string.format("%.6f", langitude);          toast.maketext(getapplicationcontext(), lat+"----"+lng,toast.length_short).show();         // getting reference textview set longitude     textview tvlng = (textview) v.findviewbyid(r.id.tv1);     imageview icon = (imageview) v.findviewbyid(r.id.icons);      if(lat.equals("73.057130") && lng.equals("33.721140"))     {         icon.setimageresource(r.drawable.hbl_icon);      }     else     {          icon.setimageresource(r.drawable.alflah_icon);     }         // returning view containing infowindow contents         return v;      }  }); 

in mymap.setinfowindowadapter toast showing same latitude information window appearing not showing image in if condition , showing image in else condition.everything works fine image not showing proper kindly help. xml :

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="horizontal" >      <imageview         android:id="@+id/icons"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="5dp" />      <textview         android:id="@+id/tv1"         android:text="get directions"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_margin="5dp" />  </linearlayout> 

you should not use latlng identify marker because of this bug.

you may use title / snippet instead , make ifs on value or have map<marker, yourmodel> of markers , keep icon resource id in model.

or can use android maps extensions, adds functions marker.setdata(object) , object marker.getdata() , keep model icon resource id close marker.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -