4

startMonitoringForRegion을 호출하여 영역 모니터링을 시작했습니다. 그러나 didStartMonitoringForRegion이 두 번 호출되는 것을 발견했습니다. didEnterRegion이 두 번 호출됩니다. 하지만 startMonitoringForRegion 한 번만 호출합니다. 내 코드는 업데이트 방법은 곤하는 법을 업데이트 중지 호출하려고 멈추지 왜이 방법 후didStartMonitoringForRegion이 하나의 startMonitoringForRegion에 두 번 호출 됨

- (void) enableRegionMonitoring:(NSMutableDictionary *)locationInfoDic{ 

NSLog(@"started Loc Mon"); 
locMgr = [[CLLocationManager alloc] init]; 
[locMgr setDelegate:self]; 
NSString *locationId=[[NSString alloc]init]; 
double latitude=[[locationInfoDic objectForKey:@"lat"] doubleValue]; 
double longitude=[[locationInfoDic objectForKey:@"lon"] doubleValue]; 
if([locationInfoDic objectForKey:@"key"]){ 
    locationId=[locationInfoDic objectForKey:@"key"] ; 
}else{ 
    [email protected]"NA"; 
} 

CLLocationCoordinate2D myMonLocation = CLLocationCoordinate2DMake(latitude, longitude); 
CLRegion *myRegion = [[CLRegion alloc] 
         initCircularRegionWithCenter:myMonLocation 
         radius:100 
         identifier:locationId]; 
[locMgr startMonitoringForRegion:myRegion 
          desiredAccuracy:kCLLocationAccuracyBest]; 

} 





- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region{ 
NSLog(@"Region monitoring started\n%@",[region description]); 
} 

답변

2

디버깅을 시도하십시오. 알아낼 시간이 없다면 2nd didEnterRegion을 무시하십시오. ie didEnterRegion이 동일한 지역에 대해 연속적으로 2 회 호출 된 경우 두 번째 것을 무시합니다.

+0

이 답변은'didEnterRegion'이 두 번 호출 된 이유를 정확히 설명하지 않으므로 정답이 아닙니까? –

0
[locMgr startMonitoringForRegion:myRegiondesiredAccuracy 
     :kCLLocationAccuracyBest]; 

이 당신을 도울 것이라 생각합니다.

[locationManager stopUpdatingLocation]; 
+0

나는 그것을 시도했다. 작동하지 않았다. 또한 나는 그것이 stopUpdatingLocation과 관련 있다고 생각하지 않는다. 다시 말하지만 앱을 실행하는 동안 위치 데이터가 필요합니다. – Harikrishnan