gpt4 book ai didi

iphone - MKReverseGeocoder 的问题

转载 作者:行者123 更新时间:2023-11-28 17:43:11 27 4
gpt4 key购买 nike

出于某种原因,我无法从我的代码中获取城市(地区)的名称。请帮忙!

 - (void)viewDidLoad {
[super viewDidLoad];


self.lm = [[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone;
[lm startUpdatingLocation];

}


- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *)oldLocation {

if (!geocoder) {
geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geocoder.delegate = self;
[geocoder start];
}

NSString *lat = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *lng = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *acc = [[NSString alloc] initWithFormat:@"%f", newLocation.horizontalAccuracy];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:lat message:lng delegate:self cancelButtonTitle:acc otherButtonTitles: @"button", nil];
[alert show];
[alert release];

[lat, lng, acc release];


}

- (void) reverseGeocoder:(MKReverseGeocoder *)geo didFailWithError:(NSError *)error {
[geocoder release];
geocoder = nil;

}



- (void)reverseGeocoder:(MKReverseGeocoder *)geo didFindPlacemark:(MKPlacemark *)placemark {

**THIS IS WHERE THE ERROR IS OCCURRING** (REQUEST FOR MEMBER 'LOCALITY' IN SOMETHING NOT A STRUCTURE OR UNION)

location = [NSString stringWithFormat:@"%@", placemark.locality];
[geocoder release];
geocoder = nil;
}

最佳答案

我意识到这是一个相对较老的问题,但是......

我遇到了完全相同的问题并求助于使用 addressDictionary 地标属性,例如,

[placemark.addressDictionary objectForKey@"City"]

代替

placemark.subAdministrativeArea

我不明白为什么后者也不起作用。

关于iphone - MKReverseGeocoder 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7304022/

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