gpt4 book ai didi

当我修复坐标时,iosverseGeocoder 失败?

转载 作者:行者123 更新时间:2023-11-29 03:42:05 25 4
gpt4 key购买 nike

 CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(27.941761 , -82.171537);

MKReverseGeocoder *reverseGeocoder =[[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
NSLog(@"%g",coordinate.latitude);
NSLog(@"%g",coordinate.longitude);
reverseGeocoder.delegate = self;
[reverseGeocoder start];
//????????????????????????????????????????????????????????????????????????

}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{

NSLog(@"current place is :%@",placemark);
}

当我使用手写坐标时,反向地理编码失败。但是当我使用从 (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 获取的 - 坐标时,成功。为什么?

最佳答案

当我将您的代码放入测试项目时,它对我来说工作得很好:

2013-08-16 23:45:55.966 TestMapApp[11261:a0b] 27.9418
2013-08-16 23:45:55.967 TestMapApp[11261:a0b] -82.1715
2013-08-16 23:45:57.831 TestMapApp[11261:a0b] current place is :6015 W Farkas And Turkey Creek Rd, Plant City, FL 33567, United States @ <+27.94176100,-82.17153700> +/- 0.00m

这是我认为出了问题的地方。您使用的是 ARC,并且没有将“reverseGeocoder”保存在任何地方(例如在 ivar 或属性中),因此一旦您创建“reverseGeocoder”的函数完成,ARC发布它。

其他一些事情:

如果委托(delegate)方法中有可用的错误参数,您应该使用它们。像这样:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
NSLog(@"MKReverseGeocoder has failed with error %@.", [error localizedDescription]);
}

最后也是最重要的是,“MKReverseGeocoder”自 iOS 5 起已被弃用。它很可能会在未来的 iOS 版本中消失。您应该尝试寻找替代品来用于反向地理编码。

关于当我修复坐标时,iosverseGeocoder 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18284677/

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