【发布时间】:2012-11-17 06:11:10
【问题描述】:
我需要获取用户的确切当前地址(国家、州、城市)。所以我去查找经纬度,然后通过使用反向地理编码从中找出。但无法自行获取纬度和经度。我使用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。但是还是看不到位置.....?是吗?
【问题讨论】:
-
Xcode 和这个问题真的没有任何关系...
标签: ios core-location cllocationmanager