我與locationManager's
didUpdateToLocation
委託但我想知道的一些價值越來越空,而我在Device
測試應用程序中使用MKReverseGeocoder
。iphone: - MKReverseGeocoder獲取POSTALCODE,subAdministrativeArea,局部性的空值和subThoroughfare
我的代碼是貝婁: -
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// this creates a MKReverseGeocoder to find a placemark using the found coordinates
reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
MKPlacemark * myPlacemark = placemark;
NSString *city = myPlacemark.thoroughfare;
NSString *subThrough=myPlacemark.subThoroughfare;
NSString *locality=myPlacemark.locality;
NSString *subLocality=myPlacemark.subLocality;
NSString *adminisArea=myPlacemark.administrativeArea;
NSString *subAdminArea=myPlacemark.subAdministrativeArea;
NSString *postalCode=myPlacemark.postalCode;
NSString *country=myPlacemark.country;
NSString *countryCode=myPlacemark.countryCode;
NSLog(@"city%@",city);
NSLog(@"subThrough%@",subThrough);
NSLog(@"locality%@",locality);
NSLog(@"subLocality%@",subLocality);
NSLog(@"adminisArea%@",adminisArea);
NSLog(@"subAdminArea%@",subAdminArea);
NSLog(@"postalCode%@",postalCode);
NSLog(@"country%@",country);
NSLog(@"countryCode%@",countryCode);
}
輸出
cityDrive-in Road
subThrough(null)
locality(null)
subLocality(null)
adminisAreaGujarat
subAdminArea(null)
postalCode(null)
countryIndia
countryCodeIN
USING CLGeocoder
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// this creates a MKReverseGeocoder to find a placemark using the found coordinates
// reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
// reverseGeocoder.delegate = self;
// [reverseGeocoder start];
CLGeocoder *reverseGeo = [[CLGeocoder alloc] init];
[reverseGeo reverseGeocodeLocation: newLocation completionHandler:
^(NSArray *placemarks, NSError *error) {
NSLog(@"%@",[placemarks objectAtIndex:0]);
for (CLPlacemark *placemark in placemarks) {
NSLog(@"~~~~~~~~%@",placemark.locality);
}
}];
}
OUTPUT IS:- ~~~~~~~~(null)
我上面的代碼在設備中正確的模擬器,但沒有工作.. :(請幫助和指導我正確的方式來獲得城市名稱
你是否能解決這個問題?我似乎得到了街道,城市,國家,除了「亞行」......爲什麼會發生這種情況?它是否與特定國家做任何事情?我來自印度。 BTW .. – GenieWanted
這是不確定每次我們得到的結果MKReverseGeocoder,因爲它已被iOS5的蘋果貶值,所以我們neet使用其替代。 –
那麼,替代解決方案是什麼? BTW。我正在使用CLGeocoder對象來進行反向地理編碼,但似乎並沒有顯示某些信息,如postalCode,subthoroughFare(門號)。對此有何想法? – GenieWanted