【问题标题】:Deprecated CLRegion methods - how to get radius?不推荐使用的 CLRegion 方法 - 如何获取半径?
【发布时间】:2014-01-28 04:27:54
【问题描述】:

我正在使用geocodeAddressString:completionHandler: 方法,它返回一个CLPlacemarks 数组。我必须得到纬度、经度、助记名称和半径。虽然获得前 3 个很容易:

double lat = placemark.location.coordinate.latitude;
double lng = placemark.location.coordinate.longitude;
NSString *name = [NSString stringWithFormat:@"%@", ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO)]

我现在不知道如何获取半径,因为 placemark.region.radius 已被弃用。任何想法现在改用什么?我在文档中找不到足够有趣的内容。

【问题讨论】:

标签: ios objective-c core-location clregion


【解决方案1】:

弃用说明是针对CLRegion 中的radius,它说要改用CLCircularRegion

注意CLCircularRegionCLRegion 的子类。
CLCircularRegion 具有与CLRegion 相同的属性(包括radius)。

如果是创建CLRegion 并打算使用其radius 属性的人,这很重要。


但是,这里是 SDK 本身(特别是 geocodeAddressString 方法)需要担心并处理它。

在 iOS 7 中,该方法确实通过为地标的 region 属性返回 CLCircularRegion 来处理它。

基本上,您不必在此处进行任何操作或更改任何内容,因为属性名称是相同的。

此代码适用于 iOS 4 到 iOS 7:

NSLog(@"radius=%f", placemark.region.radius);

【讨论】:

  • 那么我建议使用:[(CLCircularRegion*)placemark.region radius] 来避免额外的警告。感谢您的回复。
  • 是的,不幸的是,如果部署目标是 7.0,它会发出警告。如果 Deployment Target 小于 7.0 而仍在使用 iOS 7 SDK,则不会出现警告。
猜你喜欢
  • 2014-04-09
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 1970-01-01
相关资源
最近更新 更多