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秒ごとに「移動」していることをシミュレートしたいのですが、どうすればよいですか?
ありがとう!