我CLLocation
用来获取当前位置如下:
-(void)loadCurrentLocation{
if (manager==nil) {
manager=[[CLLocationManager alloc]init];
}
manager.delegate=self;
manager.desiredAccuracy=kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
- (void) viewDidLoad {
[super viewDidLoad];
[self loadCurrentLocation];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocation *loc=newLocation;
if (loc!=nil) {
self.latitude=loc.coordinate.latitude; //1
self.longitude=loc.coordinate.longitude; //2
NSLog(@"Gained Latitude:%.f",self.latitude);
NSLog(@"Gained Longitude:%.f",self.longitude);
}
}
鉴于此,latitude
并且longitude
在文件中声明如下.h
:
@interface Prayers :UIViewController<CLLocationManagerDelegate>
@property double longitude;
@property double latitude;
@end
问题是第 1 行和第 2 行的返回值是像 30 和 31 这样的整数,我期待它们像31.377033600000004000
and一样30.016893900000000000
,那么为什么返回的值是整数而不是 double 呢?提前致谢