objective c - Create a polyline on iOs map with GPS coordinate -


in app count footsteps , want know speed , want store gps coordinates draw polyline in viewcontroller. thought can store coordinate using following code:

- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"didupdatetolocation: %@", newlocation);     cllocation *currentlocation = newlocation;      if (currentlocation != nil) {         locationarray = [[nsmutablearray alloc]init];         [locationarray addobject:currentlocation];         speed = (int) currentlocation.speed * 3.6;         self.labelspeed.text = [nsstring stringwithformat:@"%d km/h",speed];         nslog(@"%@", [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.longitude]);         nslog(@"%@", [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.latitude]);     } } 

but doesn't works, because in locationarray stored last coordinates received gps sensor. explain better i'm trying develop write here specific: in first viewcontroller want show 2 label in calculate number of steps , speed. in viewcontroller i've receive coordinates data , thought data should inserted in nsmutablearray. in second viewcontroller show label in insert total number of steps (by using prepareforsegue method) , below mapview in draw polyline display path made. need coordinates received in first viewcontroller, i've pass data first second viewcontroller using prepareforsegue method. issue how can store coordinates have them in second viewcontroller draw polyline? cna me?

thank you

you storing last coordinates because initializing array every time new location, move allocation line method (like viewdidload) , erase line in didupdatetolocation.

- (void)viewdidload {     [super viewdidload];     locationarray = [[nsmutablearray alloc]init];     //.... more code }  - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"didupdatetolocation: %@", newlocation);     cllocation *currentlocation = newlocation;      if (currentlocation != nil) {         //locationarray = [[nsmutablearray alloc]init]; //this line doesn't go here         [locationarray addobject:currentlocation];         speed = (int) currentlocation.speed * 3.6;         self.labelspeed.text = [nsstring stringwithformat:@"%d km/h",speed];         nslog(@"%@", [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.longitude]);         nslog(@"%@", [nsstring stringwithformat:@"%.8f", currentlocation.coordinate.latitude]);     } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -