위치 관리자가 위치를 업데이트하지 않는 문제가 있습니다. (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLoc fromLocation:(CLLocation *)oldLoc
함수가 호출되지만 새 위치가 동일한 이전 위치로 표시됩니다. , 내가 CLLocationManager가 위치를 업데이트하지 않습니다.
-(void) viewDidLoad
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
// created a timer to call locationUpdate method
[NSTimer scheduledTimerWithTimeInterval:20 target: self selector: @selector(locationUpdate) userInfo: nil repeats: YES];
}
-(void)locationUpdate
{
[self.locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLoc
fromLocation:(CLLocation *)oldLoc
{
NSLog(@"in locationmanager did update %f",newLoc.coordinate.latitude);
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance(newLoc.coordinate, 0.01, 0.02);
[self.mapView setRegion:region animated:YES];
[self.locationManager stopUpdatingLocation];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.02);
MKCoordinateRegion region = MKCoordinateRegionMake(mapView.userLocation.coordinate, span);
[_mapView setRegion:region animated:YES];
[_mapView regionThatFits:region];
}
난 "을 locationManager에 업데이트 % f를했다"(@ NSLog에 점점 오전 값 CLLocationManager
의 객체를 생성하고 내있는 viewDidLoad 방법에서부터 newLoc : 다음코드의 내 작품이다 .coordinate.latitude)는 항상 동일하지만 현재 위치에서 2km 이상 움직였습니다.
위치 정보가있는 경우 정확한 위치를 얻는 방법을 알려주세요. 미리 감사드립니다.
왜 NSTimer를 사용하여 열악한 위치 관리자를 다시 시작 하시겠습니까? ** 문서를 읽었다면 ** startUpdatingLocation **을 한 번 호출하는 것으로 충분하다는 것을 알았을 것입니다 ** ** –
타이머를 추가하기 전에 뷰에서 한 번 [locationManager startUpdatingLocation]을 호출하려고했습니다 ,하지만 locationUpdate 대리자 메서드에서 동일한 이전 위치로 새 위치를 가져오고있었습니다. – Sonal0706
그 이유는 ... 음 .. 너는 움직이지 않는거야? –