1.初始化:
/*
* initWithPlacemark:
*
* Discussion:
* Initialize a newly allocated placemark from another placemark, copying its data.
*/
- (instancetype)initWithPlacemark:(CLPlacemark *) placemark;
2.获取位置:
/*
* location
*
* Discussion:
* Returns the geographic location associated with the placemark.
*/
@property (nonatomic, readonly, copy, nullable) CLLocation *location;
维度:placemark.location.coordinate.latitude
经度:placemark.location.coordinate.longitude
3.获取区域:一般是子类CLCircularRegion
/*
* region
*
* Discussion:
* Returns the geographic region associated with the placemark.
*/
@property (nonatomic, readonly, copy, nullable) CLRegion *region;
4.获取时区:
/*
* timeZone
*
* Discussion:
* Returns the time zone associated with the placemark.
*/
@property (nonatomic, readonly, copy, nullable) NSTimeZone *timeZone NS_AVAILABLE(10_11,9_0);
5.获取地址字典:
/*
* addressDictionary
*
* Discussion:
* This dictionary can be formatted as an address using ABCreateStringWithAddressDictionary,
* defined in the AddressBookUI framework.
*/
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary;
地址字典key值:Country:国家 State:省 City:市 SubLocality:区 Thoroughfare:街道 SubThoroughfare:子街道(门牌号) CountryCode:国家代码 name:具体位置 FormattedAddressLines:包含最详细的地址(返回的是数组)
6.获取位置名(具体位置):
@property (nonatomic, readonly, copy, nullable) NSString *name; // eg. Apple Inc.
7.获取街道:
@property (nonatomic, readonly, copy, nullable) NSString *thoroughfare; // street name, eg. Infinite Loop
8.获取子街道(门牌号):
@property (nonatomic, readonly, copy, nullable) NSString *subThoroughfare; // eg. 1
9.获取市:
@property (nonatomic, readonly, copy, nullable) NSString *locality; // city, eg. Cupertino
10.获取区:
@property (nonatomic, readonly, copy, nullable) NSString *subLocality; // neighborhood, common name, eg. Mission District
11.获取省(州):
@property (nonatomic, readonly, copy, nullable) NSString *administrativeArea; // state, eg. CA
12.获取行政信息:
@property (nonatomic, readonly, copy, nullable) NSString *subAdministrativeArea; // county, eg. Santa Clara
13.获取邮政编码:
@property (nonatomic, readonly, copy, nullable) NSString *postalCode; // zip code, eg. 95014
14.获取国家代码:中国是CN 美国是US:
@property (nonatomic, readonly, copy, nullable) NSString *ISOcountryCode; // eg. US
15.获取国家:
@property (nonatomic, readonly, copy, nullable) NSString *country; // eg. United States
16.获取水源或者湖泊:
@property (nonatomic, readonly, copy, nullable) NSString *inlandWater; // eg. Lake Tahoe
17.获取海洋:
@property (nonatomic, readonly, copy, nullable) NSString *ocean; // eg. Pacific Ocean
18.获取关联的或利益相关的地标:
@property (nonatomic, readonly, copy, nullable) NSArray<NSString *> *areasOfInterest; // eg. Golden Gate Park
注意:
1.四大直辖市的城市信息无法通过CLPlacemark的locality属性获得,只能通过访问administrativeArea属性来获得(如果locality为空,则可知为直辖市),代码参考如下:
NSString *city = placemark.locality;
if (!city) {
//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
city = placemark.administrativeArea;
}
2.上面的FormattedAddressLines可通过以下方法输出:
NSArray *formattedAddressLines = placemark.addressDictionary[@"FormattedAddressLines"];
NSString *addressString = [formattedAddressLines componentsJoinedByString:@"\n"];
NSLog(@"Address: %@", addressString);