How to get formatted address NSString from AddressDictionary?

前端 未结 9 1420
旧巷少年郎
旧巷少年郎 2020-12-17 14:58

Trying to get formatted address from AddressDictionary, that I got from CLGeocoder. Used following code with no result:

subtitle = [NSString stringWithString         


        
9条回答
  •  太阳男子
    2020-12-17 15:26

    After doing some digging under iOS 6.1 I found out that the CLPlacemark address dictionary contains a pre-formatted address:

    CLLocation *location = [[CLLocation alloc]initWithLatitude:37.3175 longitude:-122.041944];
    [[[CLGeocoder alloc]init] reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = placemarks[0];
        NSArray *lines = placemark.addressDictionary[ @"FormattedAddressLines"];
        NSString *addressString = [lines componentsJoinedByString:@"\n"];
        NSLog(@"Address: %@", addressString);
    }];
    

    I couldn't yet find documentation about this, but it works for all the addresses that I tested.

提交回复
热议问题