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.
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
[Plain]
Self. locationManager = [[CLLocationManager alloc] init]; // create a location manager
Self. locationManager. delegate = self; // sets the proxy.
Self. locationManager. desiredAccuracy = kCLLocationAccuracyBest; // specify the expected precision level.
Self. locationManager. distanceFilter = 1000.0f; // you can specify a distance filter.
[Self. locationManager startUpdatingLocation]; // start the Location Manager
NSString * str = [NSString stringWithFormat: @ "http://maps.googleapis.com/maps/api/geocode/json? Latlng = % f, % f & sensor = true®Ion = 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 stringByReplacingOccurrencesOfString: @ "" 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.