Objective c 如何从反向地理编码目标C中获取州和市

Objective c 如何从反向地理编码目标C中获取州和市,objective-c,google-api,geolocation,reverse-geocoding,Objective C,Google Api,Geolocation,Reverse Geocoding,请不要在阅读前将其标记为副本,因为在将问题发布到此处之前,我已经尝试了许多解决方案 我有纬度和经度,我试图获得城市和州的名称,但我从谷歌API的响应中感到困惑,哪一个用于城市,哪一个用于州。 有人能帮我吗 我尝试了这个代码来获取城市和州信息 CLLocation *locSource = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(pdblLatitude,pdblLongitude)

请不要在阅读前将其标记为副本,因为在将问题发布到此处之前,我已经尝试了许多解决方案

我有纬度和经度,我试图获得城市和州的名称,但我从谷歌API的响应中感到困惑,哪一个用于城市,哪一个用于州。 有人能帮我吗

我尝试了这个代码来获取城市和州信息

CLLocation *locSource = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(pdblLatitude,pdblLongitude)
                    altitude:-1
          horizontalAccuracy:200
            verticalAccuracy:200
                   timestamp:[NSDate date]];
CLGeocoder *geocoder=[[CLGeocoder alloc]init];

CLLocationCoordinate2D coord;
coord.longitude = pdblLatitude;
coord.latitude = pdblLongitude;
// or a one shot fill
     
[geocoder reverseGeocodeLocation:locSource completionHandler:^(NSArray *placemarks, NSError *error) {
    CLPlacemark *placemark = placemarks[0];
    NSDictionary *addressDictionary = [placemark addressDictionary];
    
    cityName = [addressDictionary objectForKey:@"City"];
    stateName = [addressDictionary objectForKey:@"State"];

    NSLog(@"-=====0=-==========%@",addressDictionary);
}];
但当我进入“哈里亚纳”时,它没有给我正确的细节

现在我尝试了第二种方法

[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(pdblLatitude, pdblLongitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
    NSLog(@"reverse geocoding results: %@ ----", [response results]);
    for(GMSAddress* addressObj in [response results]) {
        NSLog(@"reverse geocoding results: ^^^^^^^  %@ ^^^^^^^^^", addressObj);
        NSLog(@"thoroughfare=%@", addressObj.thoroughfare);
        NSLog(@"locality=%@", addressObj.locality);
        NSLog(@"subLocality=%@", addressObj.subLocality);
        NSLog(@"administrativeArea=%@", addressObj.administrativeArea);
        NSLog(@"postalCode=%@", addressObj.postalCode);
        NSLog(@"country=%@", addressObj.country);
        NSLog(@"lines=%@", addressObj.lines);
    }
}];
在这一点上,我对我应该用哪一个城市和哪一个国家感到困惑

为了获得纬度和经度,我使用了以下代码

#pragma Get Lat LNG by address string
-(CLLocationCoordinate2D) getLocationFromAddressString: (NSString*) addressStr andPlaceId:(NSString *)placeId{
    [ProgressHUD show:kSTRING_LOADING Interaction:NO];
    
    double latitude = 0, longitude = 0;
    NSString *esc_addr =  [addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  
    NSString *req = [NSString stringWithFormat:@"https://maps.google.com/maps/api/geocode/json?sensor=false&address=%@&key=%@", esc_addr, CONST_GOOGLE_API_KEY];
    
    NSString *response = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
    if (response) {
        
        NSString *jsonString = response;
        NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
        id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                
        NSArray *arrayResult = [json objectForKey:@"results"];
        if ([arrayResult count]>0) {
            NSDictionary *dict = [arrayResult objectAtIndex:0];
            latitude = [[[[dict objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lat"] doubleValue];
           longitude =  [[[[dict objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lng"] doubleValue];
        }
    }

    CLLocationCoordinate2D center;
    center.latitude= latitude;
    center.longitude = longitude;
    
    [ProgressHUD dismiss];
    
    return center;
}
任何人都可以帮助我或建议我什么是正确的关键字名称,以获得城市和国家的价值从谷歌API

谢谢