我需要获取用户的确切当前地址(国家、州、城市)。所以我去查找经纬度,然后通过使用反向地理编码从中找出。但无法获得经纬度本身。我正在使用 xcode 4.1 并在 iphone 模拟器中进行测试。
这是我正在处理的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
NSLog(@"%@", [self deviceLocation]);
}
- (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];
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];
longLabel.text = longt;
}
我怎样才能找到纬度和经度,从而找到用户的地址?
编辑:
将我的版本更新到 Xcode 4.5。但是还是看不到位置......?是这样吗?