Sunday, 15 May 2011

c# - gps tracking perfomance issue on Windows Phone 8 -



c# - gps tracking perfomance issue on Windows Phone 8 -

made quick app friend walks dog , wants know how far walks , speed , stuff high accuracy. anyway made app track distance , location timer. works ok when comes updating stats on screen (performed every 8 seconds) there seems performance problem time pause , jump 2 seconds if update part taking sec or 2.

here code

list<geocoordinate> locations; geolocator locator = new geolocator(); locator.desiredaccuracy = positionaccuracy.high; locator.movementthreshold = 1; locator.positionchanged += locator_positionchanged; dispatchertimer _timer = new dispatchertimer(); _timer.interval = timespan.fromseconds(1); _timer.tick += timer_tick; _timer.start(); long _starttime = system.enviroment.tickcount; private void locator_positionchanged(geolocator sender, postionchangedeventargs args) { currentlocation = args.position; if(getpositiontime >= 8) // checks see if 8 seconds has passed { deployment.current.dispatcher.begininvoke(new action(() => { geocoordinate cord = new geocoordinate(currentlocation.coordinate.latitude, currentlocation.coordinate.longitude); if(locations.count > 0) { geocoordinate previouslocation = locations.last(); // part update stats on screen textbox bound // distancemoved distancemoved = cord.getdistanceto(previouslocation); } locations.add(cord); })); } } private void timer_tick(object sender, eventargs e) { getpositiontime++; timespan time = timespan.frommilliseconds(system.enviroment.tickcount - _starttime); // update timer on screen duration = time.tostring(@"hh\:mm\:ss"); }

ui controls need updated on ui thread - wrap dispatcher.begininvoke around duration , should work.

deployment.current.dispatcher.begininvoke(new action(() => { duration = time.tostring(@"hh\:mm\:ss"); }

c# gps location windows-phone

No comments:

Post a Comment