Core Location---positioning frame
Cllocationmanager This attribute must be written as global, otherwise it will be released after initialization.
Authorized
nslocationwheninuseusagedescription : When the app is in the foreground, you can get the location information nslocationalwaysusagedescription
Control according to the actual situation.
Code that is actually authorized:
//以此来判断,是否是ios8
if
([locationManager respondsToSelector:
@selector
(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
Kclauthorizationstatusnotdetermined: The user has not been requested to obtain the authorization authorization box will only pop up once, if the customer turned off the positioning function, should pop up the prompt box.
Kclauthorizationstatusrestricted: The user has closed the location service in the settings
Kclauthorizationstatusdenied: The user received a request to obtain authorization, but clicked No, or closed in the settings
Kclauthorizationstatusauthorized: The user receives a request for authorization and clicks Yes; (this status is deprecated in iOS8, iOS7 and the following are available)
Kclauthorizationstatusauthorizedalways = kclauthorizationstatusauthorized User licensed app to get location information at any time
Kclauthorizationstatusauthorizedwheninuse: User authorized app to get location information at reception
if ([Cllocationmanager authorizationstatus]==kclauthorizationstatusdenied) { NSLog (@ "Please open Location Services"); Nsurl *settingsurl = [Nsurl urlwithstring:uiapplicationopensettingsurlstring]; [[UIApplication sharedapplication] openurl:settingsurl]; }
[Self.locationmanager startupdatinglocation]; Start location service-(void) Locationmanager: (Cllocationmanager *) Manager Didupdatelocations: (Nsarray *) Locations corresponding Proxy method
[_locationmanager stopupdatinglocation];
Positioning can consume a lot of resources, so the proxy is closed.
Now required: Get the corresponding place name based on location-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{ NSLog (@ "%@", locations.lastobject); Cllocation *location=locations.lastobject; [Self.geocoder reversegeocodelocation:location completionhandler:^ (Nsarray *placemarks, NSError *error) { Clplacemark *placemark=placemarks.lastobject; NSLog (@ "More info:%@", placemark.addressdictionary[@ "Formattedaddresslines"]); }];}
ios--positioning