i new android development taking shot @ making myself golf rangefinder.. have activity -
public class hole_1 extends activity implements view.onclicklistener { button nextbtn; gpstracker gps; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_hole_1); gps = new gpstracker(hole_1.this); // variable home activity bundle extras = getintent().getextras(); string course = null; if (extras != null) { course = extras.getstring("course"); } //set next hole button nextbtn = (button) findviewbyid(r.id.nextbutton); nextbtn.setonclicklistener(this); gps = new gpstracker(hole_1.this); if (gps.cangetlocation()) { double latitude = gps.getlatitude(); double longitude = gps.getlongitude(); double lat2 = 39.765718; double lon2 = -121.860080; location loc1 = new location(""); loc1.setlatitude(latitude); loc1.setlongitude(longitude); location loc2 = new location(""); loc2.setlatitude(lat2); loc2.setlongitude(lon2); float distanceinmeters = loc1.distanceto(loc2); int mydist = (int) (distanceinmeters * 1.0936); textview latview = (textview) findviewbyid(r.id.yardage); latview.settext(string.valueof(mydist)); }else{ gps.showsettingsalert(); } } @override public void onclick(view v) { intent myintent = new intent(this, end.class); myintent.putextra("hole",1); startactivity(myintent); } }
what update mydist variable distance between current coordinates , fixed coordinates (lat2, lon2). have done research , found asynctask, threading , setting timer cannot figure out best method application.. app works great have refresh page updated distances , update every few seconds.. should do?
thanks!
1)you can't update every couple of seconds. gps updates every 30s minute.
2)you wouldn't use async task here or oter form of threading, gps works on callback system. request updates , call whenever update available.
3)do not use gpstracker library ever. it's broken. badly. see full writeup have on why broken @ http://gabesechansoftware.com/location-tracking/
Comments
Post a Comment