2014-07-09 2 views
-1

Hiii,왜 호출하지 않는 Cllocationmanager 대리자 메서드를 사용하여 Geofence 추적을 수행합니까?

위치 관리자를 사용하여 지오 펜스를 구현했습니다.

locationManager = [[CLLocationManager alloc] init]; 
[locationManager setDelegate:self]; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
locationManager.distanceFilter = kCLLocationAccuracyBest; 
[locationManager startMonitoringSignificantLocationChanges]; 
[locationManager startUpdatingLocation]; 

-(void)TraceGeofenceLocation{ 
    for (int k=0; k< [self.chGeofenceType count]; k++) { 
    NSString *chTracLati = [NSString stringWithFormat:@"%f",[[self.chGeofenceLatitudes objectAtIndex:k] doubleValue]]; 
    NSString *chTracLong = [NSString stringWithFormat:@"%f",[[self.chGeofeceLongitudes objectAtIndex:k] doubleValue]]; 
    NSString *chTracRadius = [NSString stringWithFormat:@"%f",[[self.chGeofenceRadius objectAtIndex:k] doubleValue]]; 
     CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(chTracLati.doubleValue, chTracLong.doubleValue); 



     if ([[self.chGeofenceType objectAtIndex:k] intValue] == 1) { 

       region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Restricted"]; 
      } 
      else if ([[self.chGeofenceType objectAtIndex:k] intValue] == 2){ 

       region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"SafeZone"]; 
      } 
      else{ 
       region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:chTracRadius.doubleValue identifier:@"Curfew"]; 

      } 
      [region setNotifyOnEntry:YES]; 
      [region setNotifyOnExit:YES]; 

      [locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest]; 

     } 

    } 

추적

// 지리적 울타리로 여기

내가 만드는 오전 지역

내가 내 위임 테스트 여기

보기에서 코드가로드 내가 객체를 생성 않았다 입력 메소드는 입력 할 영역이 있으면 입력합니다. ...

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 

    locationnew = locations.lastObject; 
    self.Latit=[NSString stringWithFormat:@"%f", locationnew.coordinate.latitude]; 
    self.Longi=[NSString stringWithFormat:@"%f",locationnew.coordinate.longitude]; 
    Speed = [[NSString stringWithFormat:@"%f",[locationnew speed]] floatValue]; 

    NSLog(@"Speed :%f Latitude :%@ Longitude :%@",Speed,self.Latit,self.Longi); 

}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 

    if ([region.identifier isEqualToString:@"Restricted"]) { 

     [self sendNotificationtoServerwithtype:@"1"]; 
    } 

    else if ([region.identifier isEqualToString:@"Curfew"]){ 

     [self sendNotificationtoServerwithtype:@"3"]; 
    } 

} 

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { 

     if ([region.identifier isEqualToString:@"SafeZone"]){ 

     [self sendNotificationtoServerwithtype:@"2"]; 
    } 

} 


- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region 
{ 
    if (state == CLRegionStateInside){ 
     NSLog(@"is in target region"); 

    }else{ 
     NSLog(@"is out of target region"); 
    } 

} 

내 대리자 메서드 업데이트 위치가 호출되고 난 콘솔, 에서 얻을 수 있지만, 지역의 지역, 출구에 입력하고 DetermineState 호출되지 않았다

아무도 나를 도와 줄 수 없어. 사전

답변

0

startUpdatingLocation에서

덕분에startMonitoringSignificantLocationChanges는 상호 배타적입니다. 지오 펜스를 찾으려면 시작 모니터링 중요한 위치 변경을 수행하려면 stopUpdatingLocation으로 먼저 전화하십시오.

또한 지오 펜스 탐지가 엄청나게 정확하지 않습니다. 평균적으로 수백 미터의 해상도를 낼 수 있습니다. 나는 didEnterRegion이 종종 호출되기까지 몇 분이 걸리는 것을 발견했습니다.

참고 : 현재 [locationManager startMonitoringForRegion : region desiredAccuracy : kCLLocationAccuracyBest]를 호출하고 있습니다. 이 문제는 kCLLocationAccuracyBest가 정말 작은 영역이라는 것입니다. (값 1.0의 kCLLocationAccuracyBest 코드). 즉, 직경 1.0 미터의 구역으로 들어갈 때 알려주도록 시스템에 요청하는 것입니다. 지오 펜스 감지에는 수백 미터의 정확도가 있기 때문에 결코 호출되지 않을 수 있습니다. 대신 정확도를 훨씬 낮은 것으로 설정해야합니다. [locationManager startMonitoringForRegion : region desiredAccuracy : 200.0];

행운을 빈다.

관련 문제