I'm using the following code to create a list of markers in a mapfragment using three arrays that sends the information of latitude, longitude and name of one list of records. My objective is to get send to a new intent the name of the record when the info window is clicked. Now sends for all markers the recordname of the last item of the array but I need send the specific info to each marker. Any idea?
String[] arraylatitud = arrlat.toArray(new String[arrlat.size()]);
String[] arraylongitud = arrlon.toArray(new String[arrlon.size()]);
String[] arrayrecordname = arrrecname.toArray(new String[arrrecname.size()]);
for(int i=0; i<arrlon.size();i++){
mapa.addMarker(new MarkerOptions()
.position(new LatLng(Float.valueOf (arraylatitud[i]),Float.valueOf (arraylongitud[i])))
.title("Grabación:" + arrayrecordname[i])
.snippet("Latitud:" + arraylatitud[i] + "Longitud:" + arraylongitud[i]));
filename = arrayrecordname[i];
}
mapa.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapArea.this, StreamingArea.class);
intent.putExtra("variable_selection", filename.toString());
startActivity(intent);
}
}
I've just made a blog post on this. You can find it at: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
Every marker has got an Id.
if you store that id, along with the information you need you can get the right info back