在我的应用程序中,我计算了脚步声,现在我想知道速度,我想存储 GPS 坐标以在另一个 ViewController 中绘制一条折线。我认为我可以使用以下代码存储此坐标:
- (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]);
}
}
但它不起作用,因为locationArray
它只存储了 GPS 传感器接收到的最后一个坐标。为了更好地向您解释我正在尝试开发的内容,我将在这里写一些更具体的内容:在第一个 ViewController 中,我想显示 2 个标签,我在其中计算步数和速度。所以在这个 ViewController 中我必须接收坐标数据,我认为这个数据应该插入到NSMutableArray
. 在第二个 ViewController 中,我显示了一个标签,我将在其中插入总步数(通过使用prepareForSegue
方法),在 MapView 下方,我将在其中绘制一条折线以显示我制作的路径。为此,我需要在第一个 ViewController 中收到的坐标,所以我必须通过使用将数据从第一个 ViewController 传递到第二个 ViewControllerprepareForSegue
方法。我的问题是如何存储所有坐标以将它们放在第二个 ViewController 中以绘制折线?有人帮我吗?
谢谢