0

次のコードを使用して現在の国を取得しています

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCodes = [locale objectForKey:NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey:NSLocaleCountryCode value:countryCodes];
NSLog(@"%@",countryName);

私は UAE にいますが、これは米国を示しています。iPod でテストしています。現在の国を取得する方法を教えてください。

4

1 に答える 1

2
-(void)viewWillAppear:(BOOL)animated
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    [super viewWillAppear:animated];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    geoCoder.delegate = self;
    [geoCoder start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    NSLog(@"Detail is:--> %@",placemark);

    NSString *strCountry = [NSString stringWithFormat:@"Current Cuntry %@",[placemark.addressDictionary objectForKey:@"Country"]];

    NSLog(@"label detail is:--> %@",strCountry);

    lblAddress.text = strCountry;
}

このコードを試してください...これにより、現在の国の詳細が確実に得られます。

于 2012-07-26T07:19:48.773 に答える