dictionary - Create an Android GPS tracking application -


recently i've taken android development hobby , looking develop application can find , track users position using google maps.

once application has gps lock, application can track movements drawing route using overlay class.

i've seen similar applications mytracks open source they're complex me right now.

ideally i'd love create application looks this

he code below without imports.

what i'm trying create array of geopoints. every time location changes new geopoint created. try use loop iterate through each geopoint , draw path between them.

public class tracking extends mapactivity implements locationlistener {  locationmanager locman; locationlistener loclis; location location; private mapview map;  list<geopoint> geopointsarray = new arraylist<geopoint>(); private mapcontroller controller; string provider = locationmanager.gps_provider; double lat; double lon;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.map);     initmapview();     initmylocation();     locman = (locationmanager) getsystemservice(context.location_service);     // locman.requestlocationupdates(provider,60000, 100,loclis);     // location = locman.getlastknownlocation(provider);  }  /** find , initialize map view. */ private void initmapview() {     map = (mapview) findviewbyid(r.id.map);     controller = map.getcontroller();     map.setsatellite(false);     map.setbuiltinzoomcontrols(true); }  /** find current position on map. */ private void initmylocation() {     final mylocationoverlay overlay = new mylocationoverlay(this, map);     overlay.enablemylocation();     overlay.enablecompass(); // not work in emulator     overlay.runonfirstfix(new runnable() {         public void run() {             // zoom in current location             controller.setzoom(24);             controller.animateto(overlay.getmylocation());         }     });     map.getoverlays().add(overlay); }  @override public void onlocationchanged(location location) {     if (location != null) {         lat = location.getlatitude();         lon = location.getlongitude();         geopoint new_geopoint = new geopoint((int) (lat * 1e6),                 (int) (lon * 1e6));         controller.animateto(new_geopoint);      }  }  class myoverlay extends overlay {     public myoverlay() {     }      public void draw(canvas canvas, mapview mapv, boolean shadow) {         super.draw(canvas, mapv, shadow);          projection projection = map.getprojection();         path p = new path();         (int = 0; < geopointsarray.size(); i++) {             if (i == geopointsarray.size() - 1) {                 break;             }             point = new point();             point = new point();             projection.topixels(geopointsarray.get(i), from);             projection.topixels(geopointsarray.get(i + 1), to);             p.moveto(from.x, from.y);             p.lineto(to.x, to.y);         }         paint mpaint = new paint();         mpaint.setstyle(style.stroke);         mpaint.setcolor(0xffff0000);         mpaint.setantialias(true);         canvas.drawpath(p, mpaint);         super.draw(canvas, map, shadow);     } }  @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  }  @override protected boolean isroutedisplayed() {     // todo auto-generated method stub     return false; } } 

the application runs fine without errors there no path drawn, location dot moves move.

any appreciated thanks.

the source code android mobile application open-gpstracker appreciated available here.

you can checkout code using svn client application or via git:

debugging source code surely you.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -