Basic knowledge of iOS-GPS Positioning
The iOS-GPS positioning service and map application are two completely different APIs.
Four positioning services for iOS 7
GPS satellite advantages of the most accurate, disadvantages of power consumption, can not block (building can not) WI-FI through WIFI router positioning advantages of power saving, economic benefits cellular mobile phone base station. The positioning error of Mobile Carrier Base Stations is relatively large. IBeacon developed by Apple uses Bluetooth with low power consumption. IOS positioning service development does not need to specify the positioning path (except for micro-positioning). ios uses the best solution based on the device's situation. If GPS is acceptable, GPS positioning is preferred, followed by Wi-Fi, finally, the positioning of cellular base stations;
Using the Core Location framework for the positioning service in iOS 7
CLLocationManager is used to locate the management class. It provides location information and Height Information. It can also monitor the device's entry or exit from a certain area and obtain the operation direction of the device. CLLocationManagerDelegate. The delegate protocol of the CLLocationManager class. CLLocation encapsulates the location and height information. When you request the location information for the first time, the system will prompt you whether to enable the location service.
- (void)viewDidLoad{ [super viewDidLoad]; locationManager = [[CLLocationManager alloc]init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = 1000.f;}
Initialize a location manager and set the proxy
DesireAccuracy is used to set the longitude
KCLLocationAccuracyBest; battery-powered high-precision compaction; precise to 10 meters kCLLocationAccuracyHundredMeters; precise to 100 meters kCLLocationAccuracyKilometer; precise to 1000 meters; accurate to 3000 meters
The higher the longitude, the shorter the information retrieval time. The more power consumption you need.
The distabceFilter attribute defines the minimum distance to obtain location information after a device moves, in meters;
Sets the distance filter distanceFilter, indicating that the device moves at least 1000 meters to notify the delegated update.
Enable and disable the positioning service when the view is displayed.
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [locationManager startUpdatingLocation];}- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [locationManager stopUpdatingLocation];}
Call a proxy to obtain data when the location is obtained successfully.
-(Void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray *) locations {CLLocation * currentLocation = [locations lastObject]; double altitude = currentLocation. altitude; // height double latitude = currentLocation. coordinate. latitude; double longpolling = currentLocation. coordinate. longpolling ;}
In the proxy, lication is the array of location data, and the last is the current location;
Cllocation class
Initialization function-initWithLatitude: longdistance:-distance: altitude: horizontalAccuracy: verticalAccuracy: timestamp:-distance: altitude: distance: verticalAccuracy: course: speed: timestamp: attribute: coordinate property geographic coordinate altitude property height horizontalAccuracy property map shows the verticalAccuracy of the circle radius verticalAccuracy property accuracy timestamp property location determined time-distanceFromLocation: speed of speed property movement from the specified location to the current location direction of the course property Device
CLLocation encapsulates information such as location and height. altitude is the height value. coordinate is the encapsulated structure of latitude and longitude. struct {CLLocationDegrees latitude; // longitude CLLocationDegrees longpolling; // latitude} CLLocationCoordinate2D; CLLocationDegrees is an alias of the double type.
All the above content comes from instructor Guan Dongsheng's ios Development Guide