Positioning of CLLocationManager and cllocationmanager in Ios development

Source: Internet
Author: User

Positioning of CLLocationManager and cllocationmanager in Ios development

The positioning function in Ios is implemented through the Core Location framework. It is independent of the map development framework. The Core Location mainly provides the Location and geographical encoding functions!

Next we will introduce its attributes, methods, and proxy methods!

  Attribute:

DesiredAccuracy: positioning accuracy, which is an enumeration type

// KCLLocationAccuracyBest: the most precise positioning

// KCLLocationAccuracyNearestTenMeters: 10 meters error range

// KCLLocationAccuracyHundredMeters: error range of meters

// KCLLocationAccuracyKilometer: kilometer error range

// KCLLocationAccuracyThreeKilometers: error range: 3 km

DistanceFilter: Minimum Distance for Location Information Update. The location information is updated only when the movement is greater than this distance. The default value is kCLDistanceFilterNone. No distance limit is imposed.

  Object method:

StartUpdatingLocation: start locating and tracing

StopUpdatingLocation: Stop locating and tracing

StartUpdatingHeading: Start direction Tracing

StopUpdatingHeading: Stop direction Tracing

StartMonitoringForRegion: Start to track a region

StopMonitoringForRegion: Stop tracking a region

RequestAlwaysAuthorizationNSLocationAlwaysUsageDescription

RequestWhenInUseAuthorization: request to obtain the positioning service authorization when the application is used. Note that you must configure this method in info. plist before using this method.NSLocationWhenInUseUsageDescription

Proxy method:

-(Void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray *) locations; execute after the location changes

-(Void) locationManager :( CLLocationManager *) manager

DidUpdateHeading :( CLHeading *) newHeading; after the navigation direction changes, run

-(Void) locationManager :( CLLocationManager *) manager

DidEnterRegion :( CLRegion *) region; enter a region

-(Void) locationManager :( CLLocationManager *) manager

DidExitRegion :( CLRegion *) region; after exiting a region, run

Open code:

//// ViewController. m // location /// Created by jerehedu on 15/12/23. // Copyright (c) 2015 jerehedu. all rights reserved. // # import "ViewController. h "# import <CoreLocation/CoreLocation. h> @ interface ViewController () <CLLocationManagerDelegate> {CLLocationManager * manager; CLGeocoder * geocoder;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,375,122)]; label. font = [UIFont systemFontOfSize: 16]; [self. view addSubview: label]; if ([CLLocationManager locationServicesEnabled]) {NSLog (@ "");} // request the user to authorize if ([CLLocationManager authorizationStatus] = kclthorizationstatusnotdetermined) {[manager requestWhenInUseAuthorization];} else if ([CLLocationManager authorizationStatus] = condition) {manager = [[CLLocationManager alloc] init]; [manager requestAlwaysAuthorization]; [manager requestWhenInUseAuthorization]; manager. delegate = self; manager. desiredAccuracy = kCLLocationAccuracyBest; // accuracy // positioning accuracy, enumeration type: // kCLLocationAccuracyBest: the most precise positioning // CLLocationAccuracy accuracy: 10 meters error range // accuracy: 3 km error range // kCLLocationAccuracyKilometer: Km error range // kCLLocationAccuracyThreeKilometers: error range manager. distanceFilter = 1.0; // move the last 10 meters to locate the location. // the minimum distance between location information updates. The location information is updated only when the distance is greater than the distance. The default value is kCLDistanceFilterNone: no distance limit [manager startUpdatingLocation];} // Do any additional setup after loading the view, typically from a nib .} -(void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray *) locations {CLLocation * loctaion = [locations firstObject]; NSLog (@ "% f", loctaion. coordinate. latitude, loctaion. coordinate. longpolling);/* [geocoder handler: loctaion completionHandler: ^ (NSArray * placemarks, NSError * error) {CLPlacemark * placemark = [placemarks firstObject]; CLLocation * location = placemark. location; // location CLRegion * region = placemark. region; // region NSDictionary * addressDic = placemark. addressDictionary; // detailed address information dictionary, which contains the following information // CLPlacemark * placemark = [placemarks firstObject]; // placemark. addressDictionary NSString * name = placemark. name; // name NSString * thoroughfare = placemark. thoroughfare; // The street NSString * subThoroughfare = placemark. subThoroughfare; // Street information, such as NSString * locality = placemark. locality; // city NSString * subLocality = placemark. subLocality; // city information, such as the landmark NSString * administrativeArea = placemark. administrativeArea; // state NSString * subAdministrativeArea = placemark. subAdministrativeArea; // other administrative region information NSString * postalCode = placemark. postalCode; // zip code NSString * ISOcountryCode = placemark. ISOcountryCode; // country Code NSString * country = placemark. country; // country NSString * inlandWater = placemark. inlandWater; // water source, Lake NSString * ocean = placemark. ocean; // ocean NSArray * areasOfInterest = placemark. areasOfInterest; // associated or stakeholder landmarks}]; */}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .}

 

Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
Copyright Disclaimer: The copyright of this article is shared by Yantai jereh Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the consent of the author and provide the original article connection clearly on the article page, otherwise, you are entitled to pursue legal liability.
Technical Consultation:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.