java - How to pass an object to Google Maps Android API V2 Marker? -
i have api witch returns json data. using gson library convert json objects java objects.
i have list filled objects each of them holds particular information (id, name, long, lat, status, street, etc). add markers map , works fine... want show additional information i.e. status, street , other info, when user clicks on 1 of markers (each markers should display different information).
so, need pass object (or data) activity show whole information of particular marker. suggest?
you can create hashmap managing mapping between markers , related information.
hashmap<marker, data> hashmap = new hashmap<marker, data>(); note: data class thet include information (id, name, long, lat, status, street, etc).
when add markers on map, need add them map (with related informations). example if have data in list:
for(data data : list){ marker marker = mmap.addmarker(new markeroptions() .position(new latlng(data.lat, data.long)); hashmap.put(marker, data); } then, supposing want use information associated marker, when click info window, can this:
mmap.setoninfowindowclicklistener(new googlemap.oninfowindowclicklistener() { @override public void oninfowindowclick(marker marker) { data data = hashmap.get(marker); if(data!=null){ intent intent = new intent(mcontext, youractivity.class); intent.putextra(youractivity.extra_message, data); mcontext.startactivity(intent); } } }); note: data should implement parcelable, or can pass id, if information retrieved json persisted, example in database, , after activity receives id, can other information database.
Comments
Post a Comment