我想扭轉地理編碼位置的緯度/長度值,我得到的應用程序,我想從這個座標來找到城市名稱,國家名稱和ISO。IOS獲取位置與CLLocationManager從經緯度
我目前使用CLLocationManager得到與如下因素代碼的實際位置信息:
//Auto geolocation and find city/country
locationManager.delegate=self;
//Get user location
[locationManager startUpdatingLocation];
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//String to hold address
locatedAtcountry = placemark.country;
locatedAtcity = placemark.locality;
locatedAtisocountry = placemark.ISOcountryCode;
//Print the location to console
NSLog(@"Estas en %@",locatedAtcountry);
NSLog(@"Estas en %@",locatedAtcity);
NSLog(@"Estas en %@",locatedAtisocountry);
[cityLabel setText:[NSString stringWithFormat:@"%@,",locatedAtcity]];
[locationLabel setText:[NSString stringWithFormat:@"%@",locatedAtcountry]];
//Set the label text to current location
//[locationLabel setText:locatedAt];
}];
它可以正常使用,但是,這是可以做到的,我已經保存在朗/緯度值相同該設備,而不是像當前位置上的實際代碼?
更新和解決方案:
感謝馬克的答案,我終於可以用下面的代碼來獲取信息,從保存的座標:
CLLocation *location = [[CLLocation alloc] initWithLatitude:37.78583400 longitude:-122.40641700];
[self.geoCoder reverseGeocodeLocation: location completionHandler:
^(NSArray *placemarks, NSError *error) {
//Get nearby address
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//String to hold address
locatedAtcountry = placemark.country;
locatedAtcity = placemark.locality;
locatedAtisocountry = placemark.ISOcountryCode;
//Print the location to console
NSLog(@"Estas en %@",locatedAtcountry);
NSLog(@"Estas en %@",locatedAtcity);
NSLog(@"Estas en %@",locatedAtisocountry);
[cityLabel setText:[NSString stringWithFormat:@"%@",locatedAtcity]];
[locationLabel setText:[NSString stringWithFormat:@"%@",locatedAtcountry]];
//Set the label text to current location
//[locationLabel setText:locatedAt];
}];