android - Place markers on map with timer -
i'm adding markers (around 200) path on map using google maps v2, , placed on map. requirement add each marker time interval wanted animation. i've tried 2 methods, first method is
latvalues[] = {....}; longvalues[]={....}; for(int i=0;i<latvalues.length;i++){ map.addmarker(new markeroptions().position(new latlng(latvalues[i],longvalues[i])).title("info") .icon(bitmapdescriptorfactory.fromresource(r.drawable.img))); thread.sleep(500); }
this not working, after placing markers, map loading..
second method is
latvalues[] = {....}; longvalues[]={....}; timer marktimer = new timer(); marktimer.scheduleatfixedrate(new timertask() { @override public void run() { for(int i=0;i<latvalues.length;i++){ map.addmarker(new markeroptions().position(new latlng(latvalues[i],longvalues[i])).title("info") .icon(bitmapdescriptorfactory.fromresource(r.drawable.img))); } } },0, 500); marktimer.cancel();
this not loading markers also...
please suggest workaround achieve this...
edited code using countdown timer:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.datemap); supportmapfragment fm = (supportmapfragment)getsupportfragmentmanager().findfragmentbyid(r.id.busmap); map=fm.getmap(); map.setmylocationenabled(true); countdown(); } public void countdown(){ if(this.ctimer != null){ this.ctimer.cancel(); } this.ctimer = new countdowntimer(1000,500) { @override public void ontick(long millisuntilfinished) { // todo auto-generated method stub if(markerno<latitudevalues1.length){ map.addmarker(new markeroptions().position(new latlng(latitudevalues1[markerno],longitudevalues1[markerno])).title("info") .icon(bitmapdescriptorfactory.fromresource(r.drawable.arrow))); markerno++; } } @override public void onfinish() { // todo auto-generated method stub map.movecamera(cameraupdatefactory.newlatlngzoom(new latlng(latitudevalues1[markerno],longitudevalues1[markerno]), 12)); } }.start(); }
have tried countdowntimer?
int markerno = 0; public void startcountdown(){ if(this._countdowntimer != null){ this._countdowntimer.cancel(); } this._countdowntimer = new countdowntimer(time_for_set_in_s * 1000, 500){ @override public void onfinish() { } @override public void ontick(long millisuntilfinished) { if(markerno < longvalues.size()){ map.addmarker(new markeroptions().position(new latlng(latvalues[markerno],longvalues[markerno])).title("info") .icon(bitmapdescriptorfactory.fromresource(r.drawable.img))); markerno++ } } }.start(); }
Comments
Post a Comment