陈斌彬的技术博客

Stay foolish,stay hungry

使用INTULocationManager实现定位

info.plist中加入两个键值:

NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription

使用方法如下,两个方法分别用于获取当前位置和持续获取位置,使用block回传消息,因此需要注意调用顺序:

- (void)viewDidLoad {  
[super viewDidLoad];  

INTULocationManager *locMgr = [INTULocationManager sharedInstance];  
// 获取当前位置  
[locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyRoom timeout:10.0 block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {  

    NSLog(@"%f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);  

}];  

// 申请持续获取位置  
[locMgr subscribeToLocationUpdatesWithBlock:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {  

    NSLog(@"%f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);  

}];  

}

Resource Reference