CLLocation
我有一个从文件中解析的对象数组。我想模拟用户正在沿着这条路线移动,我已经实现了这个:
for (CLLocation *loc in simulatedLocs) {
[self moveUser:loc];
sleep(1);
}
这是循环中调用的方法:
- (void)moveUser:(CLLocation*)newLoc
{
CLLocationCoordinate2D coords;
coords.latitude = newLoc.coordinate.latitude;
coords.longitude = newLoc.coordinate.longitude;
CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinate:coords];
annotation.title = @"User";
// To remove the previous location icon
NSArray *existingpoints = self.mapView.annotations;
if ([existingpoints count] > 0) {
for (CustomAnnotation *annotation in existingpoints) {
if ([annotation.title isEqualToString:@"User"]) {
[self.mapView removeAnnotation:annotation];
break;
}
}
}
MKCoordinateRegion region = { coords, {0.1, 0.1} };
[self.mapView setRegion:region animated:NO];
[self.mapView addAnnotation: annotation];
[self.mapView setCenterCoordinate:newLoc.coordinate animated:NO];
}
但在运行 iPhone 模拟器时,只有数组中的最后一个位置及其区域会显示在 mapView 中。我想模拟用户每 1 秒“移动”一次,我该怎么做?
谢谢!