To get the current position, it takes only 2 steps to complete
1: Determine if the device supports positioning, and then create a Mkmapview
if ([Cllocationmanager locationservicesenabled]) { =[[Mkmapview alloc] init]; Mymapview. delegate= self; Mymapview.showsuserlocation=YES; }
2: implementing the Mkmapviewdelegate protocol
-(void) Mapview: (Mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation{//get latitude and longitudeCllocation *newlocation=userlocation.location; NSLog (@"Locaiton---%f---%f", Userlocation.coordinate.latitude,userlocation.coordinate.longitude); //Anti-geo-codingClgeocoder *clgeocoder=[[Clgeocoder alloc] init]; Clgeocodecompletionhandler Handle=^ (Nsarray *placemarks,nserror *error) { for(Clplacemark *placemarkinchplacemarks) { //Get Location nameNsdictionary *addressdic=placemark.addressdictionary; NSString*state=[addressdic Objectforkey:@" State"]; NSString*city=[addressdic Objectforkey:@" City"]; NSString*sublocality=[addressdic Objectforkey:@"sublocality"]; NSString*street=[addressdic Objectforkey:@"Street"]; NSLog (@"%@%@%@", State,sublocality,street); } };//Execution[Clgeocoder reversegeocodelocation:newlocation completionhandler:handle];}
Then the positioning of the current position is complete, the code is very small, but also very simple
IOS Clgeocoder geo-coding for geolocation