Deprecated CLRegion methods - how to get radius?

自古美人都是妖i 提交于 2019-12-08 17:15:02

问题


I'm using the geocodeAddressString:completionHandler: method, which returns an array of CLPlacemarks. I have to get latitude, longitude, mnemonical name and radius. While getting the first 3 is easy:

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

I don't know how to get the radius now, as placemark.region.radius is deprecated. Any ideas what to use now instead? I can't find anything interesting enough in documentation.


回答1:


The deprecation note is for radius in CLRegion and it says to use CLCircularRegion instead.

Note that CLCircularRegion is a subclass of CLRegion.
CLCircularRegion has the same properties that CLRegion had (including radius).

This matters if you are the one creating a CLRegion with the intention of using its radius property.


However, here, it is the SDK itself (specifically the geocodeAddressString method) which has to worry about it and handle it.

In iOS 7, that method indeed handles it by returning a CLCircularRegion for the placemark's region property.

Essentially, you don't have to do or change anything here since the property names are identical.

This code will work from iOS 4 to iOS 7:

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


来源:https://stackoverflow.com/questions/21023307/deprecated-clregion-methods-how-to-get-radius

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!