iOS cannot specify which targeting method to use, depending on the device and the surrounding environment to adopt a set of the best solution.
In the relocation service application, the first time the location information is requested, the user is prompted whether to allow location services to be enabled.
iOS mainly uses three classes to achieve positioning:
1) Cllocationmanager, used to locate service management class, it can provide us with location information and height information.
2) Cllocationmanagerdelegate, which is the Cllocationmanager class of the trust agreement
3) Cllocation. This class encapsulates position and height information
The Desiredaccurecy property of the Cllocationmanager class has 6 values.
Kcllocationaccuracynearesttenmeters, accurate to 10 meters
Kcllocatinaccuracyhundredmeters, precise 100 meters
Kcllocatinaccuracykilometer, accurate to 1000 meters
Kcllocatinaccuracythreekilometer, accurate to 3000 meters
Kcllocatinaccuracybest, highest accuracy when using battery power
Kcllocatinaccuracybestfornavigation, maximum accuracy in the case of navigation
Two agent methods:
Locationmanager:didupdatelocations: Positioning success
Locationmanager:didfailwitherror: Failed to locate
The code is as follows:
#import "LocationViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <CoreLocation/CLLocationManagerDelegate.h>
@interface Locationviewcontroller () <CLLocationManagerDelegate>
@property (nonatomic, Strong) Cllocationmanager * Locationmanager;
@end
@implementation Locationviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Initialize Locationmanager
Self.locationmanager = [[Cllocationmanager alloc] init];
Self.locationManager.delegate = self;
Self.locationManager.desiredAccuracy = Kcllocationaccuracybest;
Self.locationManager.distanceFilter = 0.1f;
}
-(void) Viewwillappear: (BOOL) animated
{
[Super viewwillappear:animated];
Start positioning
[Self.locationmanager startupdatinglocation];
}
-(void) Viewwilldisappear: (BOOL) animated
{
[Super viewwilldisappear:animated];
Stop positioning
[Self.locationmanager stopupdatinglocation];
}
#pragma mark-Proxy method
-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations
{
cllocation * location = [locations Lastobject];
NSLog (@ "%3.5f", location.coordinate.latitude);//Longitude
NSLog (@ "%3.5f", location.coordinate.longitude);//Latitude
NSLog (@ "%3.5f", location.altitude);//height
}
-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error
{
NSLog (@ "error:%@", error);
}
@end
iOS Location Services