2011-12-21 3 views
6

모니터링 지역을 사용하여 사용자가 랜드 마크를 방문했는지 추적하려고합니다. 위치 관리자는 뷰 컨트롤러의 viewDidLoad에서 mapkitiphone CLLocationmanager 지역 모니터링 콜백이 트리거되지 않았습니다.

와 함께의 ViewController 초기화된다

if (self.locationManager == nil) 
{ 
    //  NSLog(@"creating location manager"); 
    self.locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
} 


NSSet* set=[locationManager monitoredRegions]; 

if ([CLLocationManager regionMonitoringAvailable] && [CLLocationManager regionMonitoringEnabled]) { 
    NSLog(@"region monitoring okay"); 
    NSLog(@"monitored regions: %@",set); 
} 

제가 정확하게 모든 영역 "괜찮 모니터링 영역의"NSLogs을 얻는다. 지역의 추가

그렇게

double metres=20.0; 
CLLocationDistance dist=metres; 
CLLocationAccuracy acc=1.0; 

CLRegion *reg=[[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:dist identifier:landmarkObj.landmarkName]; 

[locationManager startMonitoringForRegion:reg desiredAccuracy:acc]; 

처럼 수행되지만 콜백 모든 그러나 위치를 업데이트

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Entered" 
                message:region.identifier 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Exited" 
                message:region.identifier 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region 
{ 
    NSLog(@"started monitring for region: %@",region); 
} 

- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error 
{ 
    NSLog(@"%@",error); 
} 

을 유발하지 않는, 잘 작동합니다. 대신 지역에 대한 모니터링하는 데 사용 didUpdatToLocation :

[locationManager startUpdatingLocation]; 

예상

업데이트로 콜백 didUpdateToLocation을 트리거합니다. 여전히 이것이 작동하지 않는 이유를 알고 싶습니다. 지역 모니터링에 성공한 사람이 거의없는 것처럼 보입니다.

+0

이 문제에 대한 해결책을 찾아 냈습니까? 같은 문제가 있고 didStartMonitoringForRegion이 실행되지 않습니다. – Das

+0

지역 모니터링만으로는 내가 필요한 정밀도를주지 못하는 것으로 나타났습니다. 나는 모든 didUpdateToLocation 콜백에 대한 수동 검사를 끝내었다. 이것은 내가 10 지역만을 추적했기 때문에 가능했다. – tzl

답변

3

영역 추적 내용은 낮은 세분성 위치 추적을위한 것이며 셀 위치 경계에서 트리거되므로 셀 경계를 넘지 않으면 영역을 확인하지 않습니다. 저도 같은 문제를했고,이 연구되고 다른 웹 사이트는이 애플 포럼에 지적이에 대한 코멘트했다 :이 작동하지 않는 이유를 이해할 수 모든 의견을 읽으면

https://devforums.apple.com/message/251046#251046

합니다.

추적 된 CLRegions 및 점령 된 CLRegions을 포함하도록 내 NSSets를 정의한 곳에서 작업을 시도하고있는 경우 locationManager를 얻은 경우 : didUpdateToLocation : fromLocation : 콜백, 추적 된 세트의 모든 영역을 확인하여 inRegions 세트에 없었지만 현재 추적 된 지역 (inRegions에 추가하고 enterRegion으로 콜백) 또는 inRegion 이었지만 현재 (inRegions에서 제거하고 exitRegion으로 콜백) 오전. 지금 진행중인 작업입니다.

+0

아니요,이 경우는 아닙니다. 동일한 셀 캐리어에 두 개의 다른 장치가 있으므로 하나의 영역에서만 작동하지만 다른 장치에서는 작동하지 않습니다. – uofc

+0

그래, 그렇습니다. 관련된 다른 문제가 있기 때문에 전체 사례가 아닐 수도 있지만 셀 타워 적용 범위를 중심으로 변화하는 셀과 물건을 트리거합니다. GPS가 비싸기 때문에 보통 GPS를 사용하지 않습니다. 아마 그것에 대한 뉘앙스와 엣지 케이스 및 wifi와 관련된 다른 것들이 많이 있습니다. 위의 사과 링크를 읽고 문제에 대한 더 나은 이해를 얻으십시오. – chadbag

0

CLLocationManagerDelegate을 ViewController에 설정 했습니까?

@interface Maps : UIViewController <CLLocationManagerDelegate>{ 
... 
} 
+0

예. \t @interface TrailViewController : UIViewController tzl

+2

이것은 실제로는 관련이 없다. 선언에 프로토콜을 두지 않으면 컴파일러 경고 및 내용에만 영향을 미치지 만 실제 대리인은 대리인에게 다시 호출되지 않습니다. – chadbag

0

디버그를 사용하십시오 -> 위치 -> 고속도로 드라이브 시뮬레이션을 위해, 나는 비슷한 문제를 가지고,하지만 난 몇 가지 영역을 생성하고 didEnterRegion 이상 1.000 미터에 따라 트리거됩니다 ... 내가 돈 방법을 알지 못합니다. 내가 설정했습니다 :

locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 
locationManager.distanceFilter = kCLDistanceFilterNone; 
0

센터 좌표는 무엇입니까? 그 부분은 당신의 실례에서 빠져 있습니다. 다른 예제를 보았습니다. 정확한 위치 좌표를 반경과 결합하여 채우지 않았습니다. 반경 20m에서 트리거하려면 꽤 정확한 좌표 (5 또는 6 소수점)를 입력해야합니다.

다른 모든 것들이 꽤 좋아 보입니다.

+0

나는 6 개의 소수를 사용하고 있습니다. 내가 가장 당황스럽게 생각하는 것은 didStartMonitoringForRegion이 트리거되지 않는다는 것입니다 : S – tzl

+0

큰 반경을 시도해 볼 수 있습니다. AppDelegate로 모든 것을 옮긴 후에 만 ​​지역을 사용할 수있었습니다. 그런 다음 필요한 모든 콜백을 받았습니다. –

0

plist에 NSLocationAlwaysUsageDescription이 필요하며 앱에서 [locationManager requestAlwayAuthorization]을 호출해야합니다. NSLocationWhenInUseUsageDescription은 영역 모니터링을 해제합니다.

관련 문제