In the previous section we obtained longitude and latitude values by positioning, but it is difficult for the average person to understand these figures.
Geo-Information anti-coding: is based on these latitude and longitude to return the location of the relevant text description information , these text description information is encapsulated in the Clplacemark class , we call this class "Landmark" class.
Geo-Information anti-coding is implemented using the Clgeocoder class, which enables the conversion between geographic coordinates and geographic text description information.
In the Clgeocoder class, the Geocoding method for geo-information is : reversegeocodelocation: Completionhandler:
Location: Is the Geolocation object to locate
Completionhandler: A code block was specified for the callback after geo-location.
-(Ibaction) Reversegeocode: (ID) sender{Clgeocoder*geocoder =[[Clgeocoder alloc] init]; [GeoCoder reversegeocodelocation:_currlocation Completionhandler:^ (Nsarray *placemarks, Nserror *error) { //The resulting array placemarks is an array of Clplacemark objects, just the first one.Clplacemark*mark =Nil; if([Placemarks Count] >0){ IDTempmark = [Placemarks objectatindex:0]; if([Tempmark Iskindofclass:[clplacemarkclass]]) {Mark=Tempmark; } //Specific business logic, there are many properties of Clplacemark, including the street name and other related attributesnsdictionary*addressdict =mark.addressdictionary; NSString*address =[addressdict Objectforkey: (nsstring) Kabpersonaddressstreetkey]; Address= Address = = Nil?@"": Address; NSString*state =[addressdict Objectforkey: (nsstring) Kabpersonaddressstatekey]; State= state = = Nil?@"": State; NSString*city =[addressdict Objectforkey: (nsstring) Kabpersonaddresscitykey]; City= City = = Nil?@"": City; //gets a landmark corresponding to a readable text message that is typically returned to the UI displayNSString *streetinfo = [NSString stringWithFormat:@"%@\n%@\n%@\n", state,address,city]; } }];}
"description":
_currlocation is a member variable of type cllocation and is obtained in the delegate method Locationmanager:didupdatelocations:.
completionhandler:^ (Nsarray *plackmrks, nserror *error) parameter Placemarks is a landmark collection of successful anti-coding. If the user wants to see all of the landmark information, they need to iterate through it.
The following keys are constants defined in the AddressBook framework and need to be introduced into the Addressbook.framework framework:
Kabpersonaddressstreetkey key: Can take out the street information of the landmark from the dictionary
Kabpersonaddressstatekey key: You can remove the state, province and other information of the landmark from the dictionary.
Kabpersonaddresscitykey key: Can be removed from the dictionary of the City of Landmarks and other information