【发布时间】:2012-02-18 09:24:14
【问题描述】:
我正在使用以下代码获取当前位置,我已经添加了核心定位框架
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Latitude : %@",lat);
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Longitude : %@",longt);
//longLabel.text = longt;
}
但我得到的是默认值,即纬度:42° 17' 36.8898" 和经度:-71° 27' 43.1003" 我当前的纬度:N 12° 56' 11.5624" 和经度:E 77° 32' 41.0834"。如何获得准确的纬度和经度。 我在哪里做错了,或者我需要添加任何其他方法或功能或框架。
提前致谢。
【问题讨论】:
-
你是在真机还是模拟器上测试的?
-
您是否在设备上启用了定位服务?
-
@XSlash 我在模拟器上测试过。
-
@H2CO3 我没有检查设备
-
您是否在 XCode 上启用了位置模拟器?
标签: iphone objective-c core-location latitude-longitude