CLLocationManager位置服务对象和地图的简单结合使用
来源:互联网 发布:制作淘宝店铺标志 编辑:程序博客网 时间:2024/06/07 00:03
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 1.创建地图视图对象
_mapView = [[MKMapViewalloc] initWithFrame:self.view.bounds];
// 设置地图模式
_mapView.mapType =MKMapTypeStandard;
[self.viewaddSubview:_mapView];
// 2.创建位置服务对象
_locationManager = [[CLLocationManageralloc] init];
// 设置代理的对象
_locationManager.delegate =self;
// 设置精准度
[_locationManagersetDesiredAccuracy:kCLLocationAccuracyBest];
// 如需定位服务
/* iOS8.0如需使用位置服务
requestAlwaysAuthorization -->询问是否允许访问你的位置(永久授权)
NSLocationAlwaysUsageDescription -->requestWhenInUseAuthorization(使用中授权)
注意:此处需要在plist文件中配置key
1.永久授权设置 NSLocationAlwaysUsageDescription (配置Value可以设置字符串,会显示在弹出视图中)
2.使用中授权设置 NSLocationWhenInUseUsageDescription (配置Value可以设置字符串,会显示在弹出视图中)
*/
if ([_locationManagerrespondsToSelector:@selector(requestWhenInUseAuthorization)]) {
// [_locationManager requestAlwaysAuthorization];
[_locationManagerrequestWhenInUseAuthorization];
}
// 开始定位
[_locationManagerstartUpdatingLocation];
}
/*
CLLocation用来表示某个位置的地理信息,比如经纬度、海拔等等
(1)经纬度
@property(readonly, nonatomic) CLLocationCoordinate2D coordinate;
(2)海拔
@property(readonly, nonatomic) CLLocationDistance altitude;
(3)路线,航向(取值范围是0.0° ~ 359.9°,0.0°代表真北方向)
@property(readonly, nonatomic) CLLocationDirection course;
(4)行走速度(单位是m/s)
@property(readonly, nonatomic) CLLocationSpeed speed;
(5)计算2个位置之间的距离
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location方法
*/
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// 1.停止定位
[_locationManagerstopUpdatingLocation];
// 2.设置地图现实自身位置
_mapView.showsUserLocation =YES;
// 3.获取当前手机位置
CLLocation *location = [locations lastObject];
//
// 4.设置地图显示区域
// 地图缩放比例
MKCoordinateSpan span =MKCoordinateSpanMake(.1,.1);
// 地图显示区域
MKCoordinateRegion region = MKCoordinateRegionMake(location.coordinate, span);
[_mapViewsetRegion:region];
}
- CLLocationManager位置服务对象和地图的简单结合使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 地图之CLLocationManager的使用
- 定位服务 CLLocationManager 的简单用法
- 使用CLLocationManager简单定位
- 地图之CLLocationManager的使用 定位功能使用
- Android基于位置的服务开发,百度地图的使用
- 使用ArcGIS结合下载的谷歌卫星地图搭建自己的地图服务
- iOS 高德地图 百度地图 以及苹果自带的地图URI的使用 以及CLLocationManager的使用
- 百度地图线路规划 + 地理编码结合使用,精确找到终点的位置
- IOS8 使用CLLocationManager定位服务问题
- 位置与地图:地图的使用
- 利用腾讯位置服务API实现简单的网页地图显示
- [转] iOS --- LLDB调试命令初探
- [小米]字符串重组
- postgresql教程
- centos 6.5 安装mongodb2.6
- nim语言
- CLLocationManager位置服务对象和地图的简单结合使用
- STRTOK函数的用法
- Codeforces Round #310 (Div. 1)B,C,D(set+线段树)
- [CEOI1997]参观洞穴 解题报告
- 序列化和反序列化
- mako模板调试与使用技巧
- Mysql主从复制原理
- Scramble String
- Nagel算法