One: Import frame
#import <CoreLocation/CoreLocation.h>
Two: Set Proxy and properties
<cllocationmanagerdelegate>
@property (nonatomic, strong) Cllocationmanager *locmgr;
Three: Method realization
-(Cllocationmanager *) locmgr
{
#warning Location services are not available
If(![ Cllocationmanager locationservicesenabled]) return nil;
if (! _locmgr) {
Create a location manager
self. Locmgr = [[Cllocationmanager alloc] init];
// set up proxy
Self . Locmgr. delegate = self ;
}
return _locmgr;
}
-(void) Viewdidload {
[Super Viewdidload];
//Start locating the user's location
[self. Locmgr startupdatinglocation];
}
#pragma mark-cllocationmanagerdelegate
/**
* It will be called as long as the user's location is located (very high frequency of calls)
* @param locations: loaded with Cllocation object
*/
-(void) Locationmanager: (cllocationmanager *) Manager didupdatelocations: (nsarray *) Locations
{
1. Remove Position Object
cllocation *loc = [locations firstobject];
2. remove longitude and latitude
cllocationcoordinate2d coordinate = loc.coordinate;
3. print latitude and longitude
NSLog (@ "didupdatelocations------%f%f", coordinate. latitude, coordinate. longitude);
//Stop positioning (power-saving measures: Stop Location Services immediately if you do not want to use location services )
[Manager Stopupdatinglocation];
}
/**
* Calculates the straight line distance between 2 latitude and longitude degrees
*/
-(void) countlinedistance
{
//Calculate The straight line distance between 2 latitude and longitude
cllocation *loc1 = [[cllocation alloc] initwithlatitude: Longitude: $];
cllocation *loc2 = [[cllocation alloc] initwithlatitude: Longitude: $];
cllocationdistance distance = [Loc1 distancefromlocation:loc2];
NSLog (@ "%f", distance);
}
iOS targeting--corelocation