CLLocationmanager不会经常调用更新位置委托

时间:2013-05-24 16:34:29

标签: iphone ios6 cllocationmanager

我正在使用cllocation manager在我的应用程序委托类中获取用户当前位置。这样的事情:

-(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);
}

纬度和经度在.h: @property(非原子,赋值)CLLocationDegrees纬度; @property(nonatomic,assign)CLLocationDegrees经度;

通过这种方式,我可以获得当前位置,但如果我从模拟器调试器中快速更改lat和long,则无法更新。

然后在我的视图控制器中,我很容易访问纬度和经度属性,如下所示:

-(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:@"stack@over.com", 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;)因此进入我的视图控制器。 请提出建议?

1 个答案:

答案 0 :(得分:0)

它似乎是模拟器问题,因为概述here.您是否可以在实际设备上测试它?