Saturday, May 4, 2013

[android help] 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 now i want each information window of marker must be unique i have written xml for information window but its not working aaccordingly everytime a single image shows up.



// Setting a custom info window adapter for the google map
myMap.setInfoWindowAdapter(new InfoWindowAdapter() {

// Use default InfoWindow frame

public View getInfoWindow(Marker arg0) {
return null;
}

// Defines the contents of the InfoWindow

public View getInfoContents(Marker marker) {

// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(
R.layout.info_window_layout, null);

// Getting the position from the 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 to the TextView to 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 the view containing InfoWindow contents
return v;

}

});


in myMap.setInfoWindowAdapter the toast is showing the same latitude but the information window appearing is not showing the image in if condition and always showing a image in else condition.everything works fine but the image is not showing proper kindly help. my xml is :




android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

android:id="@+id/icons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" />

android:id="@+id/tv1"
android:text="Get Directions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" />




.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...