CLGeocoder和向后兼容性

Mat*_*ahé 6 iphone backwards-compatibility reverse-geocoding ios5

我有一个简单的问题.

MKReverseCoder已弃用,自iOS 5起无效.我们必须使用CLGeocoder.但是,iOS4下有很多人.新应用如何与iOS4和iOS5配合使用进行地理编码?

谢谢!

小智 8

如果有人试图从MKReverseGeocoder转移到CLGeocoder,那么我写了一篇可能有帮助的博客文章http://jonathanfield.me/jons-blog/clgeocoder-example.html

基本上是一个例子,在您创建了locationManager和CLGeocoder对象后,只需将此代码添加到您的代码中viewDidLoad(),然后制作一些标签或文本区域来显示数据.

[super viewDidLoad]; locationManager.delegate = self; [locationManager startUpdatingLocation];

locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.CLGeocoder reverseGeocodeLocation: locationManager.location completionHandler: 
 ^(NSArray *placemarks, NSError *error) {

     CLPlacemark *placemark = [placemarks objectAtIndex:0];

         isoCountryCode.text = placemark.ISOcountryCode;
         country.text = placemark.country;
         postalCode.text= placemark.postalCode;
         adminArea.text=placemark.administrativeArea;
         subAdminArea.text=placemark.subAdministrativeArea;
         locality.text=placemark.locality;
         subLocality.text=placemark.subLocality;
         thoroughfare.text=placemark.thoroughfare;
         subThoroughfare.text=placemark.subThoroughfare;
         //region.text=placemark.region;

}];
Run Code Online (Sandbox Code Playgroud)


jus*_*tin 4

MKReverseGeocoder仍然适用于 iOS5。它只是被弃用,这意味着它会在以后的某个时候被删除(比如在 iOS6 之类的版本发布时)。所以您现在可以继续使用它,没有任何问题