IOS8 previously used corelocation to locate 1, first define a global variable to record Cllocationmanager object, introduce corelocation.framework use #import @property (nonatomic, strong) Cllocationmanager *locationmanager; 2. Initialize Cllocationmanager and start positioning self.locationmanager = [[Cllocationmanager alloc]init];_locationmanager.delegate = self; _locationmanager.desiredaccuracy = Kcllocationaccuracybest;_locationmanager.distancefilter = 10; [_locationmanager startupdatinglocation]; 3, the implementation of Cllocationmanagerdelegate agent method (1) to obtain the location data, returned is an array of cllocation, generally use one of them-(void) Locationmanager: ( Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{cllocation *currlocation = [Locations LastObject] ; NSLog (@ "Longitude =%f latitude =%f height =%f", CurrLocation.coordinate.latitude, CurrLocation.coordinate.longitude, Currlocation.altitude);} (2) To obtain a callback method for user location data failure, this notifies the user-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error{if ([error code] = = kclerrordenied) {//Access Denied} if ([error code] = = Kclerrorlocationunknown) {//Cannot get location information}} 4, viewwilldisappear off location-(void) viewwilldisappear :(BOOL) animated{[Super viewwilldisappear:animated]; [_locationmaNager stopupdatinglocation];} IOS8 using Corelocation to locate 1, you need to call the following function "IOS8 private" before using Corelocation: IOS8 has made some modifications to the positioning, including the method of locating authorization, Cllocationmanager adds the following two methods: (1) Always allow access to location information-(void) requestalwaysauthorization; (2) Allow access to location data during application-(void) Requestwheninuseauthorization; Example: Self.locationmanager = [[Cllocationmanager alloc]init];_ Locationmanager.delegate = Self;_locationmanager.desiredaccuracy = Kcllocationaccuracybest;_ Locationmanager.distancefilter = 10; [_locationmanager requestalwaysauthorization];//Add this sentence [_locationmanager startupdatinglocation]; 2. Add the following configuration to the Info.plist file: (1) nslocationalwaysusagedescription (2) Nslocationwheninuseusagedescription The value of these two keys is the description of the authorization alert, the sample configuration is as follows [Check show Raw keys/values to add]:ios8_location_info_plist.png
Using Corelocation in iOS8