2017-02-17 68 views

回答

1

通过以下方法更新CLLocation值。有迹象表明,你可以从CLPlacemark可以使用placemark.administrativeArea获得

-(void)getLocationDetails:(CLLocation *)location{ 
    CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init]; 
     [reverseGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { 
     CLPlacemark *myPlacemark = [placemarks objectAtIndex:0]; 
     NSString *countryCode = myPlacemark.ISOcountryCode; 
     NSString *countryName = myPlacemark.country; 
     NSString *cityName= myPlacemark.subAdministrativeArea; 
     NSLog(@"My country code: %@ and countryName: %@ MyCity: %@", countryCode, countryName, cityName); 
    }]; 
} 
+0

它显示码字和码字也是错误.... – sp309

+0

当我试图CLLocation *位置= [[CLLocation的alloc] initWithLatitude:19.0760经度:72.8777];它给我*我的国家代码:IN和国家/地区名称:印度MyCity:孟买* – kb920

+0

给我你正在尝试的纬度经度值。 – kb920

1

国家获取各种信息。

CLLocation *loc = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude 
        ]; 
[ceo reverseGeocodeLocation:loc 
      completionHandler:^(NSArray *placemarks, NSError *error) { 
       CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
       NSLog(@"placemark %@",placemark); 
       //String to hold address 
       NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; 
       NSLog(@"addressDictionary %@", placemark.addressDictionary); 

       NSLog(@"placemark %@",placemark.region); 
       NSLog(@"placemark %@",placemark.country); // Give Country Name 
       NSLog(@"placemark %@",placemark.locality); // Extract the city name 
       NSLog(@"location %@",placemark.name); 
       NSLog(@"location %@",placemark.ocean); 
       NSLog(@"location %@",placemark.postalCode); 
       NSLog(@"location %@",placemark.subLocality); 

       NSLog(@"location %@",placemark.location); 
       //Print the location to console 
       NSLog(@"I am currently at %@",locatedAt); 

       NSLog(@"state name %@",placemark.administrativeArea); 
       _City.text=[placemark.addressDictionary objectForKey:@"City"]; 
       [locationManager stopUpdatingLocation]; 
      } 

]; 
} 
1

您可以使用反向地理代码获取它。看下面的例子:

geocoder = [[CLGeocoder alloc] init]; 

//newlocation is CLLocation object you need to pass user location there. 

[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
     if (error == nil && [placemarks count] > 0) { 
      placemark = [placemarks lastObject]; 
      // placemark.administrativeArea is state of use 

     } else { 
      NSLog(@"%@", error.debugDescription); 
     } 
    }]; 

从CLPlacemark.h://地标字典包含用户的其他信息将如下所示。

@property (nonatomic, readonly) NSString *name; // eg. Apple Inc. 
@property (nonatomic, readonly) NSString *thoroughfare; // street address, eg. 1 Infinite Loop 
@property (nonatomic, readonly) NSString *subThoroughfare; // eg. 1 
@property (nonatomic, readonly) NSString *locality; // city, eg. Cupertino 
@property (nonatomic, readonly) NSString *subLocality; // neighborhood, common name, eg. Mission District 
@property (nonatomic, readonly) NSString *administrativeArea; // state, eg. CA 
@property (nonatomic, readonly) NSString *subAdministrativeArea; // county, eg. Santa Clara 
@property (nonatomic, readonly) NSString *postalCode; // zip code, eg. 95014 
@property (nonatomic, readonly) NSString *ISOcountryCode; // eg. US 
@property (nonatomic, readonly) NSString *country; // eg. United States 
@property (nonatomic, readonly) NSString *inlandWater; // eg. Lake Tahoe 
@property (nonatomic, readonly) NSString *ocean; // eg. Pacific Ocean 
@property (nonatomic, readonly) NSArray *areasOfInterest; // eg. Golden Gate Park