MapView에 startUpdatingLocation의 대리자를 사용하여 CLLocationManager에서 가져온 사용자의 현재 위치를 표시하도록 요청하고 MapView에 일부 주석을 추가하지만 문제는지도에서 일부 주석을 표시하기 위해 스크롤 할 때입니다. 보다 정확한이나 최근의 위치가를 얻거나 분명 장치가 이동되는 경우 경우 didUpdateToLocation
대리자 메서드를 여러 번 호출 할 수 있습니다MapView가 현재 위치 주석으로 돌아갑니다.
- (void)viewDidLoad
{
[super viewDidLoad];
// Get the location if the user
_locationManager = [[CLLocationManager alloc] init];
if ([CLLocationManager locationServicesEnabled])
{
_locationManager.delegate = self;
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[_locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// set the map view to the current location
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.05;
MKCoordinateRegion region;
region.span = span;
region.center = _locationManager.location.coordinate;
[self.mapView setRegion:region animated:YES];
}