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