Valdis Azamaris Valdis Azamaris - 4 months ago 44
Java Question

Android google maps add to marker own tag

I have such code:

protected void onPostExecute(final ArrayList<HashMap<String, String>> adapter) {

for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Log.e("pppppos", String.valueOf(pos.latitude));
Marker m = map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool"));

map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", id);
startActivityForResult(nextScreen, 0);
}
});
}


But i need to set invisible to user field for example
Tag_id
for each marker, and use this id then when sending extra info to other activity, something like:

protected void onPostExecute(final ArrayList<HashMap<String, String>> adapter) {

for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Marker m = map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool")
.Tag_id(TAG_ID));

map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", marker.get(TAG_ID));
startActivityForResult(nextScreen, 0);
}
});
}


Is it real to do? Just how can i in my listener get what marker i'm clicking?

Also it could be done via title field... But i'm getting error's when writing
marker.getTitle()
...

upd

for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Log.e("pppppos", String.valueOf(pos.latitude));
HashMap<Marker, String> m = new HashMap<Marker, String>();
m.put( map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool")), "1");

}

map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(HashMap<Marker, String> marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", "1");
startActivityForResult(nextScreen, 0);
}
});

Answer
  1. You may use Map<Marker, String> and keep your data there or
  2. use Android Maps Extensions which adds getData and setData functions to Marker class.

Btw. You should not set InfoWindowAdapter in a loop. It makes no sense. Only the last survives.