Using corelocation positioning in iOS8

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.