IOS Corelocation Regional Monitoring

Source: Internet
Author: User

Corelocation area monitoring, from crazy iOS handouts

1. Lead corelocation frame, import header file

#import <CoreLocation/CoreLocation.h>

2. Add location management as member variable, add lazy load

@property (Nonatomic,strong) Cllocationmanager *locmgr;
1 /**2 * Lazy Loading3  */4-(Cllocationmanager *) Locmgr5 {6     if(_locmgr = =Nil) {7_locmgr =[[Cllocationmanager alloc]init];8_locmgr.Delegate=Self ;9     }Ten     return_locmgr; One}

3. Open Area Monitoring

1- (void) Viewdidload2 {3 [Super Viewdidload];4 5     //setting up the center6cllocationcoordinate2d coordinate = Cllocationcoordinate2dmake ( the, the);7     //Set Radius8Cllocationdistance distance = -;9     //Create a monitoring areaTenClregion *region = [[clcircularregion alloc]initwithcenter:coordinate radius:distance Identifier:@" Region"]; One      A     //Start Area detection - [Self.locmgr startmonitoringforregion:region]; -}

4. Adding Proxy methods

1 #pragmaMark-cllocationmanagerdelegate2- (void) Locationmanager: (Cllocationmanager *) Manager didstartmonitoringforregion: (clregion *) Region3 {4NSLog (@"successfully open area monitoring");5 }6 7- (void) Locationmanager: (Cllocationmanager *) Manager didenterregion: (clregion *) Region8 {9NSLog (@"you've entered the surveillance area .");Ten } One  A- (void) Locationmanager: (Cllocationmanager *) Manager didexitregion: (clregion *) Region - { -NSLog (@"you've left the surveillance area ."); the      -     //Closed Zone monitoring -     if([Region.identifier isequal:@" Region"]) { - [Self.locmgr stopmonitoringforregion:region]; +     } -  +}

IOS Corelocation Regional Monitoring

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.