First step: Import header File
#import <CoreLocation/CoreLocation.h> #import <CoreLocation/CLLocationManagerDelegate.h>
Step two: Set up the agent
Cllocationmanagerdelegate
Step Three: Create a property
@property (nonatomic, strong) Cllocationmanager *locationmanager;
Fourth Step: Initialize
Location Services Management Object Initialization _locationmanager = [[Cllocationmanager alloc] init]; _locationmanager.delegate = self; _locationmanager.desiredaccuracy = Kcllocationaccuracybest; _locationmanager.distancefilter = 100.F; Set the minimum move of 1000 meters to refresh
Fifth step: Implement the Proxy method
#pragma mark-Implement location Refresh-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{CLL Ocation *currlocation = [locations Lastobject]; NSLog (@ "longitude =%f latitude =%f height =%f", CurrLocation.coordinate.latitude, CurrLocation.coordinate.longitude, Currlocation.altitude);}
Sixth step: Start positioning
-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated]; [_locationmanager startupdatinglocation]; Start positioning}
Seventh Step: End positioning
-(void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated]; [_locationmanager stopupdatinglocation]; Stop positioning}