@ Weng Ah Wei Ah authorized this site reproduced
Corelocation
1. Positioning
Steps to use:
Create the Cllocationmanager sample and need to strongly reference it
Set the agent for Cllocationmanager, listen and get the updated location
Start Location Update
| 123 |
_manager?=?[[CLLocationManager?alloc]?init];_manager.delegate?=?self;[_manager?startUpdatingLocation]; |
As the iOS8 requires the developer to proactively request authorization from the system, the following steps are required in the iOS8 and above systems:
Set nslocationwheninuseusagedescription or nslocationalwaysusagedescription in the Info.plist file
Using [_manager Requestwheninuseauthorization] to request authorization in code
Implementing the manager's Proxy method Didchangeauthorizationstatus: To determine whether to initiate a location update based on the state
Parametric analysis
In the manager's proxy method Locationmanager:didupdatelocations:, its incoming locations parameter is the cllocation type.
Main parameters of the Cllocation method:
| 12345678 |
//经纬度@property(readonly,?nonatomic)?CLLocationCoordinate2D?coordinate;//海平面@property(readonly,?nonatomic)?CLLocationDistance?altitude;//速度@property(readonly,?nonatomic)?CLLocationSpeed?speed//当前时间戳@property(readonly,?nonatomic,?copy)?NSDate?*timestamp; |
2. Direction
Use steps
and positioning the same three steps, the difference is that the acquisition direction does not require authorization
| 123 |
_manager?=?[[CLLocationManager?alloc]?init];_manager.delegate?=?self;[_manager?startUpdatingHeading]; |
Parametric analysis
In the manager's proxy method locationmanager:didupdateheading:, its incoming newheading parameter is the clheading type.
Main parameters of the Clheading method:
| 1234 |
//与磁北方向的偏角@property(readonly,?nonatomic)?CLLocationDirection?magneticHeading;//与正北方向的偏角@property(readonly,?nonatomic)?CLLocationDirection?trueHeading; |
3. Regional monitoring
Use steps
It also takes roughly three steps, with the first two steps as well as the positioning, and the third step is to create a scope:
| 12345678 |
_manager?=?[[CLLocationManager?alloc]?init];_manager.delegate?=?self;if?([[UIDevice?currentDevice].systemVersion?doubleValue]?>=?8.0)?{???[_manager?requestAlwaysAuthorization];}CLLocationCoordinate2D?coordinate?=?CLLocationCoordinate2DMake(32.656688,?110.74677);CLCircularRegion?*circular?=?[[CLCircularRegion?alloc]?initWithCenter:coordinate?radius:1000?identifier:@"bourne"];[_manager?startMonitoringForRegion:circular]; |
Proxy method (one in and one out)
| 12345678 |
//进入范围时调用-?(void)locationManager:(CLLocationManager?*)manager?didEnterRegion:(CLRegion?*)region?{????NSLog(@"我进来了!");}//离开范围时调用-?(void)locationManager:(CLLocationManager?*)manager?didExitRegion:(CLRegion?*)region?{????NSLog(@"我出去了!");} |
Help: In the iOS8.3 seems to have no effect, the real machine and simulator are not, iOS7.1 normal work! I don't know what's going on, if anyone knows what I want to tell me. Thank you.
4. Geocoding & Geo-coding
The so-called geocoding is you give him a place name, it returns to you here the latitude and longitude information; anti-geocoding is you give him a latitude and longitude, it returns you a place name. If you do not use the location function, you do not need authorization.
Geo-coding
| 12345 |
_coder?=?[[CLGeocoder?alloc]?init];[_coder?geocodeAddressString:@"湖北汽车工业学院"?completionHandler:^(NSArray?*placemarks,?NSError?*error)?{???CLPlacemark?*marks?=?placemarks.firstObject;???NSLog(@"%f?-?%f",?marks.location.coordinate.latitude,?marks.location.coordinate.longitude);}]; |
There are many properties available in Clplacemark, so you can go inside and see.
Anti-geo-coding
| 123456 |
CLLocation?*loc?=?[[CLLocation?alloc]?initWithLatitude:32.656688?longitude:110.74677];[_coder?reverseGeocodeLocation:loc?completionHandler:^(NSArray?*placemarks,?NSError?*error)?{???for?(CLPlacemark?*mark?in?placemarks)?{???????NSLog(@"%@",?mark.name);???}}]; |
Simple to implement, the key is how to use the data!
Extended
Corelocation use is still more troublesome, need authorization, judge the system version and so on, so we recommend using a third-party framework, such as: Locationmanager is very good, using block, very simple!
Ios-corelocation: No matter where you are, I will find you!