【发布时间】:2014-07-15 16:32:39
【问题描述】:
下面是我的 CLLocationManagerDelegate 的代码。我使用以下方法调用委托方法:
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
委托方法:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//get current location of phone:
if (newLocation != nil) {
_m.longitude = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.longitude];
_m.latitude = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.latitude];
_m.timestamp = newLocation.timestamp;
NSLog(@"didUpdateToLocation: %@", newLocation);
}
CLLocation *currentLocation = newLocation;
}
当我调用 didUpdateToLocation 方法时,我通过调试验证了 newLocation 不为零。 _m 是在我的标题中声明的对象,也不是 nil。 locationManager 也是如此。但是,当我尝试设置 _m.latitude 等并 NSLog 它们时,它们都显示为(null)。 didUpdateToLocation NSLog 结果如下:
didUpdateToLocation: +/- 65.00m(速度 -1.00 mps / 路线 -1.00)@ 2014 年 7 月 15 日,太平洋夏令时间上午 9:26:07
我不确定我哪里出错了。
【问题讨论】:
-
什么是
_m?什么显示为(null)?您应该使用locationManager:didUpdateLocations:您使用的方法自 iOS 6.0 以来已被弃用。 -
_m 是一个包含纬度、经度和时间戳的对象,分别为 NSString、NSString 和 NSDate。
-
您如何记录值?试试 NSLog(@"Cord: %.f", cord);
-
使用你的 NSLog 语句,我得到纬度 0 和经度 48。
-
尝试使用@"%.8lf" 而不是@"%.8f"。
标签: ios objective-c exif cllocation