我有一个CLLocation从文件中解析的对象数组.我想模拟用户沿着那条路线移动,我已经实现了这个:
for (CLLocation *loc in simulatedLocs) {
[self moveUser:loc];
sleep(1);
}
Run Code Online (Sandbox Code Playgroud)
这是循环中调用的方法:
- (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: …Run Code Online (Sandbox Code Playgroud)