Use of IOS corelocation

Source: Internet
Author: User

1. Introduction frame, Import header file

#import <CoreLocation/CoreLocation.h>

2. Add the Location Manager as a member variable (otherwise it cannot be located) and instantiate it with a lazy-loaded method

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

3. Start positioning

1 -(void) viewdidload2{3    [Super Viewdidload]; 4 5     // Start Positioning 6     [Self.locmgr startupdatinglocation]; 7     8 }

4. Implementing the Cllocationmanager Proxy method

1 #pragmaProxy methods for Mark-cllocationmanager2- (void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations3 {4     //take the position, the location is the array, because the location can be a location, but also may be a B location, such as Beijing and Hebei border, the general position array of the first more accurate5Cllocation *location =[Locations Firstobject];6     7     //remove longitude and latitude8cllocationcoordinate2d coordinate =location.coordinate;9     Ten     //Output OneNSLog (@"longitude is%f, latitude is%f", coordinate.longitude,coordinate.latitude); A      -     //stop positioning, the agent method calls very high frequency, do not need to locate, stop positioning - [Self.locmgr stopupdatinglocation]; the}

Use of IOS corelocation

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.