- (void) viewdidload {[Self startlocation];}//Start Positioning-(void) startlocation{Self.locationmanager=[[Cllocationmanager alloc] init]; Self.locationmanager.Delegate=Self ; [Self.locationmanager requestwheninuseauthorization]; if([[[[Uidevice currentdevice]systemversion]doublevalue]>=8.0) {[Self.locationmanager requestwheninuseauthorization]; [Self.locationmanager requestalwaysauthorization]; } [Self.locationmanager startupdatinglocation]; if([Cllocationmanager locationservicesenabled]) {self.locationManager.desiredAccuracy=kcllocationaccuracynearesttenmeters; Self.locationManager.distanceFilter=Kcldistancefilternone; }Else{NSLog (@"Open Fail"); } }#pragmaMark-corelocation Agent#pragmaMark tracks the location agent method, which is executed each time the position changes (as long as it is positioned to the appropriate location)-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{cllocation*location=[Locations Lastobject]; cllocationcoordinate2d coordinate=location.coordinate; NSLog (@"Longitude:%f, Latitude:%f", Coordinate.longitude,coordinate.latitude); Self.longitude=Coordinate.longitude; Self.latitude=Coordinate.latitude; //If you don't need real-time positioning, use it even if you turn off location services[Self.locationmanager stopupdatinglocation]; [Self Weizhi];}-(void) weizhi{Self.geocoder=[[Clgeocoder alloc]init]; Cllocation*rr=[[Cllocation alloc]initwithlatitude:self.latitude longitude:self.longitude]; [Self.geocoder reversegeocodelocation:rr Completionhandler:^ (Nsarray *placemarks, Nserror *error) {Clplacemark*mark=[placemarks Objectatindex:0]; UILabel*currentlocation=[[uilabel Alloc]initwithframe:cgrectmake ( -, the, -, -)]; Currentlocation.text=[nsstring stringWithFormat:@"%@", mark.sublocality]; [Self.locationview addsubview:currentlocation]; }];}-(void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status{Switch(status) { Casekclauthorizationstatusnotdetermined:if([Self.locationmanager respondstoselector: @selector (requestalwaysauthorization)]) {[Self.locatio Nmanager Requestwheninuseauthorization]; } Break; default: Break; }}//This method is called when the location error occurs. - (void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (Nserror*) error{NSLog (@"error-%@", error);}
Locates the current location. There are many properties for Clplacemark, not only the current location, but also other information, follow-up research ....
IOS Targeting geo-encoding