iOS geo-Information anti-coding

Source: Internet
Author: User

By positioning we can get latitude and longitude, and geo-coding can return the relevant textual description of a place by geographical coordinates.
These descriptions are encapsulated in the Clplacemark class, and its properties are:
1) addressdictionary, Geographic Information dictionary
2) Isocountrycode,iso Country code
3) country, national information
4) PostalCode, zip code
5) Adminisrativearea, Administrative Region information
6) locality, specify City information
Personally, the value stored in the dictionary is the same as the value of the other attributes in Clplacemark.

Geo-Information anti-coding is implemented using the Clgeocoder class, which enables the conversion between geographic coordinates and geographic text description information
The code is as follows:

-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations
{
Clgeocoder * Geocoder = [[Clgeocoder alloc] init];
[Geocoder reversegeocodelocation:[locations Lastobject] completionhandler:^ (Nsarray *placemarks, NSError *error) {

if ([placemarks count] > 0) {
Clplacemark * placemark = placemarks[0];
You can use the dictionary type to obtain the geographic text information, you can use the corresponding key value in the Address Book framework to obtain the corresponding information
Nsdictionary * dict = placemark.addressdictionary;
NSString * str = [dict objectforkey: (NSString *) kabpersonaddresscitykey];//get city Info

You can also get information through property values
NSLog (@ "%@", placemark.country);//Output Country information
NSLog (@ "%@", placemark.locality);//Specify City information
NSLog (@ "%@", placemark.thoroughfare);//Specify Street-level information
}
}];
}

iOS geo-Information anti-coding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.