开发者

Setting corelocation results to NSNumber object parameters

开发者 https://www.devze.com 2023-01-02 00:44 出处:网络
This is a weird one, y\'all. - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

This is a weird one, y'all.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    CLLocationCoordinate2D coordinate = newLocation.coordinate;
    self.mark.longitude = [NSNumber numberWithDouble:coordinate.longitude];
    self.mark.latitude = [NSNumber numberWithDouble:coordinate.latitude];
    NSLog(@"Got %f %f, set %f %f", coordinate.latitude, coordinate.longitude, self.mark.latitude, self.mark.longitude);

    [manager stopUpdatingLocation];
    manager.delegate = nil;

    if (self.waitingForLocation) {
        [self completeUpload];
    }
}

The latitude and longitude in that "mark" object are synthesized parameters referring to NSNumber iVars.

In the simulator, my NSLog output for that line in the middle there reads:

2010-05-28 15:08:46.938 EverWondr[8375:207] Got 37.331689 -122.030731, set 0.000000 -44213283338325225829852024986561881455984640.000000

That's a WHOLE lot further East than 1 Infinite Loop! The numbers are different 开发者_开发问答on the device, but similar--lat is still zero and long is a very unlikely high negative number.

Elsewhere in the controller I'm accepting a button press and uploading a file (an image I just took with the camera) with its geocoding info associated, and I need that self.waitingForLocation to inform the CLLocationManager delegate that I already hit that button and once its done its deal, it should go ahead and fire off the upload. Thing is, up in the button-click-receiving method, I test see if CL is finished by testing self.mark.latitude, which seems to be getting set zero...


You are printing the pointers to the NSNumber objects as floats - that is likely to look quite different.

Use:

NSLog(@"Got %f %f, set %@ %@", coordinate.latitude, coordinate.longitude, 
      self.mark.latitude, self.mark.longitude);

... or:

NSLog(@"Got %f %f, set %f %f", coordinate.latitude, coordinate.longitude, 
      [self.mark.latitude doubleValue], [self.mark.longitude doubleValue]);
0

精彩评论

暂无评论...
验证码 换一张
取 消