iOS6 CLPlacemark显示街道名称

Al_*_*reS 4 mapkit ios ios6

我想显示用户位置的完整街道名称,下面的代码我只能显示城市名称:

-(void) reverseGeocode:(CLLocation *)location{
   CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {    
    if(error) {
        NSLog(@"Error");
        return;
    }  
    if(placemarks) {
        CLPlacemark *placemark = placemarks [0];
        NSArray *lines = placemark.addressDictionary[ @"FormattedAddressLines"];
        NSString *addressString = [lines componentsJoinedByString:@"\n"];
        NSLog(@"Address: %@", addressString);
    }
}];}
Run Code Online (Sandbox Code Playgroud)

关于如何获得街道名称的任何想法?

DrK*_*Key 10

我实际上使用此代码来获取完整的位置:

@property (nonatomic,strong) CLPlacemark *placemark;
@property (strong) CLLocationManager *gps;
@property (strong) CLGeocoder *geocoder;

- (void)viewDidLoad
{
    [super viewDidLoad];

    gps = [[CLLocationManager alloc] init];
    geocoder = [[CLGeocoder alloc] init];
    gps.delegate = self;
    gps.desiredAccuracy = kCLLocationAccuracyBest;
    [gps startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error == nil && [placemarks count] > 0) {
            placemark = [placemarks lastObject];

                aLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@",
                                placemark.thoroughfare,
                                placemark.subThoroughfare,
                                placemark.postalCode,
                                placemark.locality,
                                placemark.country];

        } else {
            NSLog(@"%@", error.debugDescription);
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

但是如果需要,您可以通过使用其他CLPlacemark属性获得更多:

从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
Run Code Online (Sandbox Code Playgroud)