Turn: ios-corelocation: Wherever you are, I will find you!

Source: Internet
Author: User

1. Positioning

Steps to use:

Create the Cllocationmanager sample and need to strongly reference it

Set the agent for Cllocationmanager, listen and get the updated location

Start Location Update

123 _manager = [[CLLocationManager alloc] init];_manager.delegate = self;[_manager startUpdatingLocation];

As the iOS8 requires the developer to proactively request authorization from the system, the following steps are required in the iOS8 and above systems:

    • Set nslocationwheninuseusagedescription or nslocationalwaysusagedescription in the Info.plist file

    • Using [_manager Requestwheninuseauthorization] to request authorization in code

    • Implementing the manager's Proxy method Didchangeauthorizationstatus: To determine whether to initiate a location update based on the state

Parametric analysis

In the manager's proxy method Locationmanager:didupdatelocations:, its incoming locations parameter is the cllocation type.

Main parameters of the Cllocation method:

12345678 //经纬度@property(readonly, nonatomic) CLLocationCoordinate2D coordinate;//海平面@property(readonly, nonatomic) CLLocationDistance altitude;//速度@property(readonly, nonatomic) CLLocationSpeed speed//当前时间戳@property(readonly, nonatomic, copy) NSDate *timestamp;

2. Direction

Use steps

and positioning the same three steps, the difference is that the acquisition direction does not require authorization

123 _manager = [[CLLocationManager alloc] init];_manager.delegate = self;[_manager startUpdatingHeading];

Parametric analysis

In the manager's proxy method locationmanager:didupdateheading:, its incoming newheading parameter is the clheading type.

Main parameters of the Clheading method:

1234 //与磁北方向的偏角@property(readonly, nonatomic) CLLocationDirection magneticHeading;//与正北方向的偏角@property(readonly, nonatomic) CLLocationDirection trueHeading;

3. Regional monitoring

Use steps

It also takes roughly three steps, with the first two steps as well as the positioning, and the third step is to create a scope:

12345678 _manager = [[ Cllocationmanager alloc] init]; _manager.delegate = self; if   ([[uidevice currentdevice].systemversion  doublevalue] >= 8.0)  {     [_manager requestalwaysauthorization]; } cllocationcoordinate2d coordinate =  Cllocationcoordinate2dmake (32.656688, 110.74677); clcircularregion *circular = [[clcircularregion alloc]  initwithcenter:coordinate radius:1000 identifier:@ "Bourne" Code class= "JS Plain"); [_manager startmonitoringforregion:circular];

Proxy method (one in and one out)

12345678 //进入范围时调用- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {    NSLog(@"我进来了!");}//离开范围时调用- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {    NSLog(@"我出去了!");}

Help: In the iOS8.3 seems to have no effect, the real machine and simulator are not, iOS7.1 normal work! I don't know what's going on, if anyone knows what I want to tell me. Thank you.

4. Geocoding & Geo-coding

The so-called geocoding is you give him a place name, it returns to you here the latitude and longitude information; anti-geocoding is you give him a latitude and longitude, it returns you a place name. If you do not use the location function, you do not need authorization.

Geo-coding

12345 _coder = [[CLGeocoder alloc] init];[_coder geocodeAddressString:@"湖北汽车工业学院"completionHandler:^(NSArray *placemarks, NSError *error) {   CLPlacemark *marks = placemarks.firstObject;   NSLog(@"%f - %f", marks.location.coordinate.latitude, marks.location.coordinate.longitude);}];

There are many properties available in Clplacemark, so you can go inside and see.

Anti-geo-coding

123456 < Code class= "JS Plain" >cllocation *loc = [[cllocation alloc] initwithlatitude:32.656688 &NBSP;LONGITUDE:110.74677]; [_coder reversegeocodelocation:loc completionhandler:^ (NSArray * Placemarks, nserror *error)  { &NBSP;&NBSP;&NBSP; for   in  placemarks)  { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; nslog (@ "%@" ,  Mark.name); &NBSP;&NBSP;&NBSP; } }];

Simple to implement, the key is how to use the data!

Extended

Corelocation use is still more troublesome, need authorization, judge the system version and so on, so we recommend using a third-party framework, such as: Locationmanager is very good, using block, very simple!

Turn: ios-corelocation: Wherever you are, I will find you!

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.