In iOS 5, Apple canceled the feature of georeverse encoding. I used this feature in my graduation project. I checked the Code in this regard, there are two good open-source libraries that can implement this function, but in the end they still call the GoogleMap API.
Https://github.com/mjisrawi/iOS-Geocoding-Services
Https://github.com/samvermette/SVGeocoder
Both open-source libraries can implement functions well, but for the purpose of learning, I wrote a code to call the GoogleMap API and JSON parsing.
1. first introduce the code of JSON-framework and asihttprequest.
2. The following is the implementation code
Self. locationmanager = [[cllocationmanager alloc] init]; // create a location manager self. locationmanager. delegate = self; // sets proxy self. locationmanager. desiredaccuracy = kcllocationaccuracybest; // specify the required precision level self. locationmanager. distancefilter = 1000.0f; // set the distance filter [self. locationmanager startupdatinglocation]; // start location manager nsstring * STR = [nsstring stringwithformat: @ "http://maps.googleapis.com/maps/api/geocode/json? Latlng = % F, % F & sensor = trueion = ZH & language = ZH-CN ", [[locationmanager location] coordinate]. latitude, [[locationmanager location] coordinate]. longpolling]; nsurl * url = [nsurl urlwithstring: Str]; asihttprequest * request = [asihttprequest requestwithurl: url]; [Request startsynchronous]; nsstring * response = [Request responsestring]; nslog (@ "% @", response); nsstring * strrrr = [Response stringbyreplacingoccurrencesofstring: @ "\ n" withstring: @ ""]; nsstring * straaa = [strrrr failed: @ "" withstring: @ ""]; nsange range = nsmakerange (11, [straaa length]-26); nsstring * strbbb = [straaa substringwithrange: range]; nsmutablearray * dictionary = [strbbb jsonvalue]; self. addressstr = [[dictionary objectatindex: 0] objectforkey: @ "formatted_address"];
3. here we need to note that the JSON string returned by GoogleMap API contains many spaces and line breaks, which leads to errors during JSON parsing. Therefore, we need to process the returned string, replace spaces and line breaks. Because this string is very complex, I finally simply used the nsange to directly extract the part of the string I needed.