java - Async and Google Maps -
i asked async , listview. have problem async , maps. want set marker json returns async. unfortunately, set default values , not want to. can help
public class markerinfo extends fragmentactivity implements onmapreadycallback { private googlemap mmap; private latlng sydney; private string longituide; private string latitude; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_marker_info); supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); bundle bundle_list = getintent().getextras(); final string name_item = bundle_list.getstring("name"); jsonobject tosend = new jsonobject(); try { tosend.put("action", "getallmarkers"); } catch (jsonexception e) { e.printstacktrace(); } jsontransmitter asynctask = (jsontransmitter) new jsontransmitter(new jsontransmitter.asyncresponse() { @override public void processfinish(string output) { try { jsonarray pages = new jsonarray(output); (int = 0; < pages.length(); ++i) { jsonobject rec = pages.getjsonobject(i); string name_task = rec.getstring("nazwa"); latitude = rec.getstring("latitude"); longituide = rec.getstring("longitude"); mmap.addmarker(new markeroptions().position(new latlng(double.parsedouble(longituide), double.parsedouble(latitude)))); } } catch (jsonexception e) { e.printstacktrace(); } } }).execute(tosend); } public void onmapready(googlemap googlemap) { mmap = googlemap; }
}
execute async map dependent operation (adding markers), after google map ready.
jsontransmitter asynctask; googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { ... mapfragment.getmapasync(this); asynctask = (jsontransmitter) new jsontransmitter(new jsontransmitter.asyncresponse() { @override public void processfinish(string output) { try { jsonarray pages = new jsonarray(output); (int = 0; < pages.length(); ++i) { jsonobject rec = pages.getjsonobject(i); string name_task = rec.getstring("nazwa"); latitude = rec.getstring("latitude"); longituide = rec.getstring("longitude"); mmap.addmarker(new markeroptions().position( new latlng(double.parsedouble(longituide), double.parsedouble(latitude)))); } } catch (jsonexception e) { e.printstacktrace(); } } }); } public void onmapready(googlemap googlemap) { mmap = googlemap; jsonobject tosend = new jsonobject(); try { tosend.put("action", "getallmarkers"); } catch (jsonexception e) { e.printstacktrace(); } asynctask.execute(tosend); }
Comments
Post a Comment