ios - How calculate "pure" moving distance in Swift? -


i write application calculates total traveled distance. want value more less accurate.

my problem when not move, location manager updates location , adds total distance ~ 1...2 meters every second horizontal accuracy 10.0 . , if stay / walk / stay, distance increasing on 60...100 meters each " standing" minute. bad me.

i can stop updating location using core motion framework , detect changing x, y, z axis cmmotionmanager. work example when walk. when driving car device not change x, y, z axis.

how calculate "pure" moving distance?

declare property pedomter

@property (nonatomic, strong) cmpedometer *pedometer; 

initialize these function supported in devices iphone 5s , above contain motion sensor chips

 if ([cmpedometer isstepcountingavailable]) {              self.pedometer = [[cmpedometer alloc] init];         }         else {              uialertview * alertview=[[uialertview alloc] initwithtitle:@"alert" message:@"distance calculation not available on device!" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil];             [alertview show];         } 

and data in handler

[self.pedometer startpedometerupdatesfromdate:[nsdate date]                                              withhandler:^(cmpedometerdata *pedometerdata, nserror *error) {                                                 dispatch_async(dispatch_get_main_queue(), ^{                                                     nslog(@"data:%@, error:%@", pedometerdata, error);                                                    nslog(@"distance:%@, pedometerdata.distance);                                                     nslog(@"steps:%@", pedometerdata.numberofsteps);                                                  });                                              }]; 

don't forget import coremotion framework


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -