I was trying to get some place lists from the google places and show it in the googlemap api v2. Also i want to show infowindow, But here i can only acess the place reference through the info window argument. And the problem is the infowindow will show the reference too. It is a nasty thing. I don't want to show it inside the infowindow, but i want the reference inside this infowindow clicklistener for passing to the method how do i do that? Any help appreciated...
Code
for(Place place : nearPlaces.results){
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Getting latitude of the place
double latitude = place.geometry.location.lat;
double longitude = place.geometry.location.lng;
// Getting name
String NAME = place.name;
// Getting vicinity
String VICINITY = place.vicinity;
//Reference of a place
String REFERENCE = place.reference;
LatLng latLng = new LatLng(latitude, longitude);
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
markerOptions.title(NAME + " : " + VICINITY);
markerOptions.snippet(REFERENCE);
markerOptions.icon(bitmapDescriptor);
// Placing a marker on the touched position
final Marker marker = mGoogleMap.addMarker(markerOptions);
mGoogleMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
double dlat=arg0.getPosition().latitude;
double dlon=arg0.getPosition().longitude;
alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, arg0.getSnippet());
}
}
);
Keep a Map<Marker, Place>
& don't put REFERENCE into the snippet.
When the info window is clicked, look up the marker in the map and get the corresponding Place
HashMap<Marker, Place> markerPlaces = new HashMap<Marker, Place>();
for(Place place : nearPlaces.results){
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Getting latitude of the place
double latitude = place.geometry.location.lat;
double longitude = place.geometry.location.lng;
// Getting name
String NAME = place.name;
// Getting vicinity
String VICINITY = place.vicinity;
//Reference of a place
String REFERENCE = place.reference;
LatLng latLng = new LatLng(latitude, longitude);
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
markerOptions.title(NAME + " : " + VICINITY);
markerOptions.icon(bitmapDescriptor);
// Placing a marker on the touched position
final Marker marker = mGoogleMap.addMarker(markerOptions);
markerPlaces.put(marker, place);
mGoogleMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
double dlat=arg0.getPosition().latitude;
double dlon=arg0.getPosition().longitude;
Place p = markerPlaces.get(marker);
alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, p.reference);
}
}
);
Or, in this instance, you could make a final reference to place and use that in the onInfoWindowClick:
for(Place place : nearPlaces.results){
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Getting latitude of the place
double latitude = place.geometry.location.lat;
double longitude = place.geometry.location.lng;
// Getting name
String NAME = place.name;
// Getting vicinity
String VICINITY = place.vicinity;
//Reference of a place
String REFERENCE = place.reference;
LatLng latLng = new LatLng(latitude, longitude);
// Setting the position for the marker
markerOptions.position(latLng);
// Setting the title for the marker.
markerOptions.title(NAME + " : " + VICINITY);
markerOptions.icon(bitmapDescriptor);
// Placing a marker on the touched position
final Marker marker = mGoogleMap.addMarker(markerOptions);
final Place p = place;
markerPlaces.put(marker, place);
mGoogleMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
arg0.hideInfoWindow();
double dlat=arg0.getPosition().latitude;
double dlon=arg0.getPosition().longitude;
alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, p.reference);
}
}
);