openstreetmap - How to draw path as user move on open street map in android app using osmdroid/osmbonus? -


this image shows red dot location updation how can join points i using osm in android app first time display map.here code creates points on each updation of location need line(path) start till destination.how can achieve that? using pathoverlay created points how can join points ll form lines?

public class autotracking extends activity   {     private mapview map;     private mapcontroller mymapcontroller;     locationmanager locationmanager;     int mincr = 10;     arraylist<overlayitem> overlayitemarray;     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_auto_tracking);          map = (mapview) findviewbyid(r.id.map);         baseactivity base_obj;         baseactivity.updatetextviewtiltle("tracking");         resources res=getresources();         drawable dr=res.getdrawable(r.drawable.ic_tracking);         baseactivity.updateicon2(dr);         map.setbuiltinzoomcontrols(true);         mymapcontroller = (mapcontroller) map.getcontroller();         mymapcontroller.setzoom(12);         //--- create overlay         overlayitemarray = new arraylist<overlayitem>();         defaultresourceproxyimpl defaultresourceproxyimpl                 = new defaultresourceproxyimpl(this);         myitemizediconoverlay myitemizediconoverlay                 = new myitemizediconoverlay(                 overlayitemarray, null, defaultresourceproxyimpl);         map.getoverlays().add(myitemizediconoverlay);         //---         locationmanager = (locationmanager)getsystemservice(context.location_service);         //for demo, getlastknownlocation gps only, not network         location lastlocation                 = locationmanager.getlastknownlocation(                 locationmanager.gps_provider);         if(lastlocation != null){           //  updateloc(lastlocation);         }         //add scale bar         scalebaroverlay myscalebaroverlay = new scalebaroverlay(this);         map.getoverlays().add(myscalebaroverlay);     }      @override     protected void onresume() {         // todo auto-generated method stub         super.onresume();         locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, mylocationlistener);         locationmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, mylocationlistener);     }     @override     protected void onpause() {         // todo auto-generated method stub         super.onpause();         locationmanager.removeupdates(mylocationlistener);     }     private void updateloc(location loc){         geopoint locgeopoint = new geopoint(loc.getlatitude(), loc.getlongitude());         polyline=new polyline();       //  geopoint gpt1 = new geopoint(locgeopoint.getlatitudee6()+ mincr, locgeopoint.getlongitudee6());        geopoint gpt2 = new geopoint(locgeopoint.getlatitudee6()+ mincr, locgeopoint.getlongitudee6() + mincr);      //  geopoint gpt3 = new geopoint(locgeopoint.getlatitudee6(), locgeopoint.getlongitudee6() );         mymapcontroller.setcenter(locgeopoint);         pathoverlay mypath = new pathoverlay(color.red, this);         mypath.addpoint(locgeopoint);      //  mypath.addpoint(gpt1);       mypath.addpoint(gpt2);       // mypath.addpoint(gpt3);         mypath.addpoint(locgeopoint);         map.getoverlays().add(mypath);         mymapcontroller.setcenter(locgeopoint);         setoverlayloc(loc);         map.invalidate();     }     private void setoverlayloc(location overlayloc){         geopoint overlocgeopoint = new geopoint(overlayloc);         //---         overlayitemarray.clear();         overlayitem newmylocationitem = new overlayitem(                 "my location", "my location", overlocgeopoint);         overlayitemarray.add(newmylocationitem);         //---     }     private locationlistener mylocationlistener             = new locationlistener(){         @override         public void onlocationchanged(location location) {             // todo auto-generated method stub             updateloc(location);         }          @override         public void onproviderdisabled(string provider) {             // todo auto-generated method stub         }          @override         public void onproviderenabled(string provider) {             // todo auto-generated method stub         }          @override         public void onstatuschanged(string provider, int status, bundle extras) {             // todo auto-generated method stub         }     };     private class myitemizediconoverlay extends itemizediconoverlay<overlayitem> {         public myitemizediconoverlay(                 list<overlayitem> plist,                 org.osmdroid.views.overlay.itemizediconoverlay.onitemgesturelistener<overlayitem> ponitemgesturelistener,                 resourceproxy presourceproxy) {             super(plist, ponitemgesturelistener, presourceproxy);             // todo auto-generated constructor stub         }         @override         public void draw(canvas canvas, mapview mapview, boolean arg2) {             // todo auto-generated method stub             super.draw(canvas, mapview, arg2);             if(!overlayitemarray.isempty()){                 //overlayitemarray have 1 element only, hard code get(0)                 geopoint in = (geopoint) overlayitemarray.get(0).getpoint();                 point out = new point();                 mapview.getprojection().topixels(in, out);                 bitmap bm = bitmapfactory.decoderesource(getresources(),                         r.drawable.user);                 canvas.drawbitmap(bm,                         out.x - bm.getwidth()/2,  //shift bitmap center                         out.y - bm.getheight()/2,  //shift bitmap center                         null);             }         }         @override         public boolean onsingletapup(motionevent event, mapview mapview) {             // todo auto-generated method stub             //return super.onsingletapup(event, mapview);             return true;         }     }  } 


Comments