2013-05-24 2 views
0

я использую менеджер cllocation для получения текущего пользователя места в моей приложении делегатой class.Some вещи, как это:CLLocation менеджер не называют места обновления delegete часто

-(void) getUserCurrentLocation 
{ 
    destinationForProgressView = .25; 
    if(![CLLocationManager locationServicesEnabled]) 
    { 
    UIAlertView *enableGpsInYourDevice = [[UIAlertView alloc] initWithTitle:@"" message:@"Go to settings and enable location services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
    [enableGpsInYourDevice show]; 
    } 

locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; 
// This is the most important property to set for the manager. It ultimately determines how the manager will 
// attempt to acquire location and thus, the amount of power that will be consumed. 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
// When "tracking" the user, the distance filter can be used to control the frequency with which location measurements 
// are delivered by the manager. If the change in distance is less than the filter, a location will not be delivered. 
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters; 
// Once configured, the location manager must be "started". 
[locationManager startUpdatingLocation]; 


} 

Я в соответствии с протоколом местоположения и реализацией его метода делегата :

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

    CLLocation *newLocation = [locations lastObject]; 

     latitude = newLocation.coordinate.latitude; 

     longitude = newLocation.coordinate.longitude; 

     NSLog(@"lattitude from appDelegate is %.8f", [[locations lastObject] coordinate].latitude); 

     NSLog(@"longitude from appDelegate is %.8f", [[locations lastObject] coordinate].longitude); 
} 

Где Lattitude и долгота в .h: @property (неатомической, ASSIGN) CLLocationDegrees широты; @property (nonatomic, assign) CLLocationDegrees longitude;

Таким образом, я могу получить текущее местоположение, но оно не обновляется, если я изменяю lat и долго быстро от отладчика симулятора.

Тогда на мой взгляд, контроллер просто я получающего доступ широты и долготы свойства, как это:

-(void) getLocationCoordinates 
{ 
    self.destinationForProgressView = .25; 


    //[DELEGATE getUserCurrentLocation];**NOTE** 

     latitude = [DELEGATE latitude]; 
     longitude = [DELEGATE longitude]; 

     if (latitude && longitude) { 
      NSString *prepareMessagebody = nil; 
      memberID = [USERDATASINGLETON getMemberID]; 
      prepareMessagebody = [NSString stringWithFormat:@"Latitude is %.8f\n Longitude is %.8f\n Member-ID is %@",latitude, longitude, memberID]; 
      NSLog(@"test %@", prepareMessagebody); 

      NSArray *reciepients = [NSArray arrayWithObjects:@"[email protected]", nil]; 

      NSArray *passingobject = [NSArray arrayWithObjects:reciepients, prepareMessagebody, nil]; 

      [self performSelector:@selector(showMailPickerwithObject:) 
         withObject:passingobject 
         afterDelay:1]; 

     } 
     else{ 
      [self showalertIfLocationServicesDisabled]; 
     } 
} 

, когда я снова сделать вызов делегировать метод см Примечание и прокомментированы код // [DeleGate getUserCurrentLocation]; Я могу получить часто обновляемые местоположения. Должен ли я снова позвонить для делегирования класса для обновления местоположения, не должен ли мой делегат обновлять местоположение (@property (nonatomic, assign) CLLocationDegrees latitude and @property (nonatomic, assign) CLLocationDegrees longitude;) и, таким образом, в моем контроллере просмотра. Пожалуйста, предложите?

+0

не понял, что вы хотите в своем вопросе ... –

ответ

0

Возможно, это проблема с симулятором, как указано here., можете ли вы проверить ее на самом устройстве?