iOS corelocation Location Services

Source: Internet
Author: User

Corelocation Import Framework: #import <CoreLocation/CoreLocation.h>

Basic properties and methods to understand:

Property:

    • Location Manager: Cllocationmanager
    • Request Location Permission: requestalwaysauthorization
    • Start Get location: startupdatinglocation
    • Stop Get location: stopupdatinglocation
    • Authorized Authentication Status: Clauthorizationstatus
    • Distance to filter positioning: Distancefilter
    • Positioning required Accuracy: desiredaccuracy
    • Information to navigate to: cllocation
    • Create latitude and longitude points: cllocationcoordinate2d

Method:

    • The authorization status has changed:

      -(void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status

    • Get to location information:

      -(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations

    • Enter the listening area:

      -(void) Locationmanager: (Cllocationmanager *) Manager didenterregion: (clregion *) region

    • To leave the listening area:

      -(void) Locationmanager: (Cllocationmanager *) Manager didexitregion: (clregion *) region

  

Basic operation of Corelocatio positioning:

After iOS8, the system will not default to help us call the location authorization, we need to proactively ask the user to grant us authorization, we need to call this method:

  [Self.mgr requestalwaysauthorization];

  And we also need to configure in the Info.plist file:

  Nslocationwheninusedescription, allowing GPS descriptions to be obtained at the front desk

Nslocationalwaysusagedescription, allows the description of GPs to be acquired in the background

#import "ViewController.h"#import<CoreLocation/CoreLocation.h>@interfaceViewcontroller () <CLLocationManagerDelegate>/** * location Manager*/@property (nonatomic, strong) Cllocationmanager*Mgr;@end@implementationViewcontroller//Lazy Loading//Create Corelocation Manager-(Cllocationmanager *) mgr{if(!_mgr) {_mgr=[[Cllocationmanager alloc] init]; }    return_mgr;}- (void) viewdidload {[Super viewdidload]; //set the location where the agent listener gets toSelf.mgr.Delegate=Self ; //Determine if the iOS8 if ([[[Uidevice currentdevice].systemversion Doublevalue] >= 8.0) {NSLog (@ "is iOS8"); Proactively require users to authorize our programs, the authorization status changes will notify the agent  [self.mgr requestalwaysauthorization];  }Else    {       //Start listening (get location started)[Self.mgr startupdatinglocation]; }    }//called when the authorization state has changed- (void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status{if(Status = =kclauthorizationstatusnotdetermined) {NSLog (@"waiting for user authorization"); }Else if(Status = = Kclauthorizationstatusauthorizedalways | |Status==kclauthorizationstatusauthorizedwheninuse) {NSLog (@"Authorized Success"); //Start Positioning[Self.mgr startupdatinglocation]; }Else{NSLog (@"Authorization Failure"); }}#pragmaMark-cllocationmanagerdelegate//called when the location information is obtained (very high frequency of calls)- (void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{//Positioning Information//cllocation *location = [locations lastobject];       }

iOS corelocation Location Services

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.