gpt4 book ai didi

ios - CLLocationManager,如何获取城市或州的全名

转载 作者:可可西里 更新时间:2023-11-01 17:05:38 25 4
gpt4 key购买 nike

我在我的 iPad 应用程序中使用 CLLocationManager 类来获取当前位置。

我正在使用下面的代码获取地址详细信息,

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSUserDefaults *oIsLocation = [NSUserDefaults standardUserDefaults];
if([oIsLocation boolForKey:@"IsLocation"])
{
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;

if (newLocation.horizontalAccuracy < 0) return;

if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
{
if(bestEffortAtLocation.coordinate.latitude != newLocation.coordinate.latitude && bestEffortAtLocation.coordinate.longitude != newLocation.coordinate.longitude)
{
[self saveLocation:newLocation];
self.bestEffortAtLocation = newLocation;
[self saveUserLocation];
}
}
}
}

我正在进行反向地理编码以获取如下详细信息:

                       NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
NSLog(@"placemark.country %@",placemark.country);
NSLog(@"placemark.postalCode %@",placemark.postalCode);
NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
NSLog(@"placemark.locality %@",placemark.locality);
NSLog(@"placemark.subLocality %@",placemark.subLocality);
NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);

placemark.locality 给出城市名称,但不像北卡罗来纳州那样仅提供全名 NC。

当我的客户在美国使用应用程序时,他们得到的不是像“北卡罗来纳”这样的全名,而是 NC,Saint Charles 得到的是 St. Charles ETC。

有什么办法可以得到全名吗?

最佳答案

以下代码将所有详细信息返回到 CLPlacemark 中。

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

CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark *placemark in placemarks) {

NSLog(@"%@",[placemark locality]);

CLPlacemark *placemark = [placemarks objectAtIndex:0];

NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
NSLog(@"placemark.country %@",placemark.country);
NSLog(@"placemark.postalCode %@",placemark.postalCode);
NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
NSLog(@"placemark.locality %@",placemark.locality);
NSLog(@"placemark.subLocality %@",placemark.subLocality);
NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);

}
}];
}

希望这对您有帮助。

关于ios - CLLocationManager,如何获取城市或州的全名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31700220/

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