This article reprinted to Http://www.tuicool.com/articles/7JBRZn
In previous versions of IOS8, we had no problem using cllocationmanager positioning, and recently in the IOS8 system it was not possible to locate .... This is a big problem!
<corelocation/corelocation.h>
@property (nonatomic, strong) Cllocationmanager *locationmanager;
2. Initialize the Cllocationmanager and start positioning
Locationmanager=[[cllocationmanager alloc] init]; Locationmanager. delegate=self; Locationmanager.desiredaccuracy=kcllocationaccuracybest; Locationmanager.distancefilter=; [Locationmanager startupdatinglocation]; //Open position
3, the implementation of Cllocationmanagerdelegate agent method
#pragma Mark Cllocationmanagerdelegate/*** get latitude and longitude */-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{Cllocation *currlocation=[locations Lastobject];Location.strlatitude=[nsstring stringwithformat:@ "%f", CurrLocation.coordinate.latitude]; location.strlongitude=[nsstring stringwithformat:@ "%f", CurrLocation.coordinate.longitude]; NSLog (@ "La---%f, lo---%f", currLocation.coordinate.latitude, CurrLocation.coordinate.longitude);} /** * location failed, callback this method */-(void) Locationmanager: (Cllocationmanager *) Manager Didfailwitherror: (Nserror *) error{ if ([error code]==kclerrordenied) { Span class= "indent" > NSLog (@ "Access Denied"); } if ([Error Code]==kclerrorlocationunknown) { NSLog (@ "Cannot get location information"); }}
Using corelocation positioning in iOS8
1, before the use of corelocation need to call the following function "IOS8 dedicated": iOS8 some changes to the location, including the method of locating authorization, Cllocationmanager added the following two methods: (1) Always allow access to location information
-(void) requestalwaysauthorization;
(2) Allow access to location data during use of the application
-(void) requestwheninuseauthorization;
Examples are as follows:
Locationmanager=[[cllocationmanager alloc] init]; Locationmanager. delegate=self; locationmanager.desiredaccuracy=kcllocationaccuracybest ; Locationmanager.distancefilter=; if (iosversion>=8) { [Locationmanager requestwheninuseauthorization]; Allow access to location data in the course of the program (iOS8 positioning required) } [Locationmanager startupdatinglocation]; Turn on positioning
2. Add the following configuration in the Info.plist file: (1) nslocationalwaysusagedescription (2) nslocationwheninuseusagedescription
After this is added, the positioning function will be able to use the normal!
IOS Cllocationmanager targeting