CLGeocoder 和向后兼容性

发布于 2024-12-10 07:48:20 字数 205 浏览 0 评论 0原文

我有一个简单的问题。

MKReverseCoder 已弃用,自 iOS 5 起不再工作。我们必须使用CLGeocoder。但是,iOS4下有很多人。新应用程序如何与iOS4和iOS5配合进行地理编码?

谢谢!

I have a simple question.

MKReverseCoder is deprecated and doesn't work since iOS 5. We have to use CLGeocoder. But, there are a lot of people under iOS4. How the new apps can work with iOS4 and iOS5 for geocoding ?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年不长 2024-12-17 07:48:21

如果有人试图从 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;

}];

If anyone is trying to move onto CLGeocoder from MKReverseGeocoder then I have written a blog post that might be of help http://jonathanfield.me/jons-blog/clgeocoder-example.html

Basically an example would be, after you have created locationManager and CLGeocoder objects just add this code to your viewDidLoad() and then make some labels or text areas to show the data.

[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;

}];
铜锣湾横着走 2024-12-17 07:48:21

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

MKReverseGeocoder still works with iOS5. It's just deprecated, which means it'll be removed at some later point (like at the release of something like iOS6). So you can continue to use it now without any issues

迟月 2024-12-17 07:48:21
- (IBAction)geoCodeLocation:(id)sender{
    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 
     ^(NSArray *placemarks, NSError *error) {
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
         NSLog(@"placemark %@",placemark);
         //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
         NSLog(@"addressDictionary %@", placemark.addressDictionary);

         NSLog(@"placemark %@",placemark.region);
         NSLog(@"placemark %@",placemark.country);  // Give Country Name 
         NSLog(@"placemark %@",placemark.locality); // Extract the city name 
         NSLog(@"location %@",placemark.name);
         NSLog(@"location %@",placemark.ocean);
         NSLog(@"location %@",placemark.postalCode);
         NSLog(@"location %@",placemark.subLocality);

         NSLog(@"location %@",placemark.location);
          //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);

         //Set the label text to current location
         [locationLabel setText:locatedAt];

     }];

有关详细信息,请参阅CLPlacemark 的属性

- (IBAction)geoCodeLocation:(id)sender{
    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 
     ^(NSArray *placemarks, NSError *error) {
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
         NSLog(@"placemark %@",placemark);
         //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
         NSLog(@"addressDictionary %@", placemark.addressDictionary);

         NSLog(@"placemark %@",placemark.region);
         NSLog(@"placemark %@",placemark.country);  // Give Country Name 
         NSLog(@"placemark %@",placemark.locality); // Extract the city name 
         NSLog(@"location %@",placemark.name);
         NSLog(@"location %@",placemark.ocean);
         NSLog(@"location %@",placemark.postalCode);
         NSLog(@"location %@",placemark.subLocality);

         NSLog(@"location %@",placemark.location);
          //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);

         //Set the label text to current location
         [locationLabel setText:locatedAt];

     }];

For more see property of CLPlacemark

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文