首页 > 移动平台 > 详细

IOS地图及定位使用

时间:2015-06-05 19:13:44      阅读:256      评论:0      收藏:0      [点我收藏+]

1.定位

定位使用CoreLocation库,引入CoreLocation/CoreLocation。创建CLLocationManager对象,使用startUpdatingLocation方法开始更新位置信息。

_mgr = [[CLLocationManager alloc] init];
[_mgr requestWhenInUseAuthorization];
_mgr.delegate = self;
[_mgr startUpdatingLocation];

更新成功后,会调用CLLocationManagerDelegate的代理方法

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations objectAtIndex:locations.count - 1];       
NSLog(@"%f,%f\n",location.coordinate.latitude,location.coordinate.longitude);
}

如果要停止更新,调用stopUpdatingLocation即可。

PS1:如果启动时提示是否打开定位,需要调用CLLocationManager对象的requestWhenInUseAuthorization。

PS2:定位用途的提示,在info.plist中添加NSLocationWhenInUseUsageDescription、NSLocationAlwaysUsageDescription添加提示

 

 

 

IOS地图及定位使用

原文:http://www.cnblogs.com/punkrocker/p/4555170.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!