gpt4 book ai didi

iOS6 CLPlacemark 显示街道名称

转载 作者:可可西里 更新时间:2023-11-01 05:04:29 24 4
gpt4 key购买 nike

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

-(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);
}
}];}

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

最佳答案

我实际上是在使用这段代码来获取完整的位置:

@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);
}
}];
}

但如果需要,您可以通过使用其他 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

关于iOS6 CLPlacemark 显示街道名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21496889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com