The core location in iOS provides positioning capabilities to locate the device's current coordinates and to get device movement information at the same time. Since the polling of the positioning device is very power-hungry, it is best to start it only on a very necessary basis.
Among the most important classes are Cllocationmanager, location management.
There are 3 ways to locate it:
1,gps, the most accurate positioning method, seemingly iphone1 is not supported.
2, cellular base station triangular positioning, such positioning in the signal base station is more accurate than the cheats city.
3,wifi, such a way seems to be the data obtained through the network operator's database, the most imprecise in 3 kinds of positioning species
How to use:
1, the introduction of Corelocation package, the general default template is not, so you need to manually import.
2, by starting the Cllocationmanager to start the location service, because the location information is required to poll, and for the program is necessary for a certain time to get, so the operation of Jade Lcationmanager most of the entrusted to complete.
Code to load Locationmanager:
Cllocationmanager *locationmanager = [[Cllocationmanager alloc] init];//Create location manager locationmanager.delegate=self; Locationmanager.desiredaccuracy=kcllocationaccuracybest; locationmanager.distancefilter=1000.0f; Start location update [Locationmanager startupdatinglocation];
Desiredaccuracy to set the accuracy of positioning, can be set to the best, the device will take the initiative to use the most accurate way to locate.
Distancefilter is a distance filter, in order to reduce the number of polling on the positioning device, the position of the change will not always go to notify the trust, but to move enough distance to notify the Trust program, its unit is meters, here is set to move at least 1000 again notify entrusted processing updates.
Startupdatinglocation is the start of location management, in general, do not need to update positioning when it is best to close it, with stopupdatinglocation, can save power.
The most frequently used methods for entrusting cllocationmanagerdelegate are:
-(void) Locationmanager: (Cllocationmanager *) Manager
Didupdatetolocation: (cllocation *) newlocation
Fromlocation: (cllocation *) oldlocation;
This approach is the method by which the delegate will run when the change is in position.
To be able to get a new position, an old position, a cllocation with longitude and latitude coordinates,
At the same time Cllocation also has a property horizontalaccuracy, used to get the level of accuracy, its size is the radius of positioning accuracy, in meters.
Assuming a value of-1, this location is not trusted.
In addition entrusted another regular usage is
-(void) Locationmanager: (Cllocationmanager *) Manager
Didfailwitherror: (Nserror *) error;
This method is called when a location error occurs.
About Core Location-ios positioning