2014-07-09 4 views
-1

НШ,Почему Геозоны отслеживание с использованием методов делегирования Cllocationmanager не призывающих

Я реализовал Geo изгороди с помощью менеджера местоположения.

Здесь я создаю регионы

введите код здесь

С учетом же нагрузки я создать объект как

// для Геозоны отслеживания

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 являются взаимоисключающими. Если вы хотите сделать startMonitoringSignificantLocationChanges для поиска геообъективов, не забудьте позвонить по телефону stopUpdatingLocation.

Также имейте в виду, что обнаружение геозонности не является невероятно точным. В среднем вы можете иметь разрешение в сотни метров. Я обнаружил, что didEnterRegion часто занимает несколько минут, чтобы их можно было назвать, если вообще.

ПРИМЕЧАНИЕ: вы в настоящее время вызываете [locationManager startMonitoringForRegion: region wishAccuracy: kCLLocationAccuracyBest]; Проблема с этим - kCLLocationAccuracyBest - очень маленькая область. (kCLLocationAccuracyBest коды для значения 1.0). Это означает, что вы просите систему сообщить вам, когда вы входите в область диаметром 1,0 метр. Поскольку обнаружение геозонности имеет точность в сотни метров, это никогда не может быть вызвано. Вместо этого вы должны установить точность на что-то гораздо ниже: [locationManager startMonitoringForRegion: region wishAccuracy: 200.0];

Удачи.

Смежные вопросы