One, simple explanation
1.CLLocationManager
Common operations and properties for Cllocationmanager
Start user location (void) startupdatinglocation;
Stop user location (void) stopupdatinglocation;
Note: When the Startupdatinglocation method is invoked, the user's position is constantly positioned, and the following method of the proxy is frequently invoked
(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations;
Every number of meters to locate once
@property (Assign, nonatomic) cllocationdistance distancefilter; Positioning accuracy (the more accurate the more power consumption) @property (assign, nonatomic) cllocationaccuracy desiredaccuracy;
Determine if the user locator service opens if ([Cllocationmanager locationservicesenabled]
Calculate the straight-line distance between two latitude and longitude, and create two position objects according to latitude and longitude cllocation *loc1=[[cllocation alloc]initwithlatitude:40 longitude:116]; Cllocation *loc2=[[cllocation alloc]initwithlatitude:41 longitude:116]; Cllocationdistance Distance=[loc1 DISTANCEFROMLOCATION:LOC2];
2.CLLocation cllocation is used to indicate geographic information for a location, such as latitude and longitude, elevation, etc.
(1) by Latitude @property (readonly, nonatomic) Cllocationcoordinate2d coordinate;
(2) Elevation @property (readonly, nonatomic) cllocationdistance altitude;
(3) route, course (value range is 0.0°~ 359.9°, 0.0° represents True North) @property (ReadOnly, nonatomic) Cllocationdirection course;
(4) Walking speed (unit is m/s) @property (readonly, nonatomic) cllocationspeed speed;
(5) Calculate the distance between 2 positions (Cllocationdistance) Distancefromlocation: (const cllocation *) Location method
3.cllocationcoordinate2d
Cllocationcoordinate2d is a structural body used to denote latitude and longitude, defined as the following typedef struct {
Cllocationdegrees latitude; Latitude
Cllocationdegrees longitude; Longitude} cllocationcoordinate2d;
Generally use the Cllocationcoordinate2dmake function to create a cllocationcoordinate2d
4.cllocationmanagerdelegate* * * * When positioning to the user's location, it will be called (the frequency of calls more frequently) * *-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations{The//locations array holds the Cllocation object, and a Cllocation object represents a position
Cllocation *loc = [locations Firstobject];
Dimension: Loc.coordinate.latitude
Longitude: Loc.coordinate.longitude
NSLog (@ "Latitude =%f, Longitude =%f", loc. Coordinate latitude, loc. coordinate);
NSLog (@ "%d", locations.count);
Stop the update location (if the location service does not need to be updated in real time, then stop the update of the location)//[Self.locmgr stopupdatinglocation];
}
Note: Do not use local variables (create a location manager) because the local variable's method ends and it is destroyed. It is recommended that you use a global variable and create it only once (using lazy loading).
--------------------------------Open Positioning-------------------------------1. Import Frame #import <corelocation/ Corelocation.h> 2. Compliance Agreement < Cllocationmanagerdelegate > 3. Define positioning manager attributes, and lazy load @property (nonatomic, Strong) Cllocationmanager * Manager; -(Cllocationmanager *) Manager { #warning location service is not available if (![ Cllocationmanager locationservicesenabled]) return nil; if (! _manager) {//Create position manager self. Manager = [[Cllocationmanager alloc] init]; Set agent self. Manager. Delegate = self; return _manager; } 4. Start positioning -(void) Viewdidload {//Set precision//precision is higher, the amount of power that consumes is greater self. Manager. desiredaccuracy = Kcllocationaccuracynea Resttenmeters; if ([[[Uidevice Currentdevice]. Systemversion Floatvalue] >= 8.0) {//Add Plsit in info. nsloc file Ationalwaysusagedescription, value can not write//[_manager requestalwaysauthorization]; Add Nslocationwheninuseusagedescription,value to the Info.plsit file without writing authorization [self. Manager requestalwaysauthorization]; }
Start positioning [self. Manager startupdatinglocation]; } |