CoreLocation MKMapView
高德开发者平台 有开发指南
iOS9配置网络:
- <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
请看这里 原文章:http://www.oschina.net/question/262659_149771?fromerr=Y0rzKueR
1. GPS定位:<CoreAudioKit/CoreAudioKit.h>
1. 基本属性:
1>
CLLocationManager:定位管理器 协议:<CLLocationManagerdelegate> 设置代理 实现方法
CLLocation:位置的具体信息(经纬度 等等)
CLHeading:设备移动方向
CLRegion:一个区域(常用子类:CLCircularRegion:圆形 CLBeaconRegion:蓝牙)
[CLLocationManager locationServicesEnabled] 定位服务是否可用
distanceFilter:自动过滤距离 移动某个距离之后重新调用代理方法 更新位置
desiredAccuracy:定位的精度
- self.manager.desiredAccuracy = kCLLocationAccuracyBest; // 最佳精度
- self.manager.pausesLocationUpdatesAutomatically = YES; // 不需要的时候可以自动暂停
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.locationManager = [[CLLocationManager alloc] init];
- self.locationManager.delegate = self;
- // 允许定位
- [self.locationManager requestAlwaysAuthorization];
- // 自动过滤距离 移动100米之后重新调用代理方法 更新位置
- self.locationManager.distanceFilter = 100.0; // 米为单位
- // iOS7的系统下 写完start就可以开始定位了
- [self.locationManager startUpdatingLocation];
- // 初始化地理编码器:
- self.geocoder = [CLGeocoder new];
- }
2> CLGeocoder 地理编码器:
创建:
- self.geocoder = [CLGeocoder new];
编码:提供某个字符串 来定位位置:- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
- [self.geocoder geocodeAddressString:self.inputLocation.text completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
- // 取出一个位置信息
- CLPlacemark *placeMark = placemarks.lastObject;
- // 输出信息
- NSLog(@"%lf %lf", placeMark.location.coordinate.latitude, placeMark.location.coordinate.longitude);
- }];
反编码:根据位置显示该地方的名字等等
- [self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
- CLPlacemark *place = placemarks.lastObject;
- self.inputLocation.text = place.name;
- NSLog(@" %@",place.name);
- }];
2. 获取位置信息:
iOS7的系统下 写完start就可以开始定位了:
- [self.locationManager startUpdatingLocation];
但是在iOS之后就需要设置是否允许定位:设置完成这个之后才可以定位
requestAlwaysAuthorization:一直允许定位
requestWhenInUseAuthorization:用户允许
在添加之前需要在info.plist 文件中添加字段:NSLocationAlwaysUsageDescription (后面的字符串知识提示的时候会显示 并没有什么用)
- [self.locationManager requestAlwaysAuthorization];
2. 地图:<MapKit/MapKit.h>
1> iOS原生地图:
前面带MK的是系统自带的地图:
MKUserLocation:地图上的大头针 有title subtitle等属性
MKMapView:用来显示地图 与视图一样 初始化需要确定frame 定位的时候需要用到coreLocation框架
showsUserLocation 设置为YES 允许跟踪定位 (MKMapView的属性)
可自定义MKAnnotation
- // 创建比例系数 显示在某个点上
- MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1, 0.1)) ;
- // 比例系数越小 放大效果越大
- self.mapView.region = region; // 系统自带
2> 高德:
多以MA开头的:
[_mapView setZoomLevel:16.0 animated:YES]; 设置缩放的比例
- // 1. 验证key
- [MAMapServices sharedServices].apiKey = @“申请的key”;
- // 2. 初始化
- mapView = [[MAMapView alloc] initWithFrame:CGRectMake(, , CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.bounds))];
- mapView.delegate = self;
- // mapView.language = MAMapLanguageEn; // 设置地图显示语言
- mapView.mapType = MAMapTypeStandard; // 地图类型
- /*
- MAMapTypeSatellite:卫星地图
- MAMapTypeStandard:标准地图
- */
- // mapView.showTraffic = YES; // 显示实时交通路况
- [self.view addSubview:mapView];
- mapView.showsUserLocation = YES;
mapView的定位模式: userTrackingMode
MAUserTrackingModeNone:不跟随用户位置,仅在地图上显示。
MAUserTrackingModeFollow:跟随用户位置移动,并将定位点设置成地图中心点
MAUserTrackingModeFollowWithHeading:跟随用户的位置和角度移动
系统的地图和 高德地图 的区别:http://www.mamicode.com/info-detail-573898.html
CoreLocation MKMapView的更多相关文章
- CoreLocation MKMapView 地图
系统自带地图 框架: CoreLocation MapKit CLLocationManager --> 定位管理者 CLGeocoder --> 地理编码器 MKMapView -- ...
- MapKit/CoreLocation框架 总结
MapKit/CoreLocation框架 /*英译 core:核心 track:踪迹 current:当前 statellite:卫星 hybird:混合 region:范围 annotation ...
- iOS - MKMapView 地图
1.创建 MKMapView 地图 在 iOS6 或者 iOS7 中实现这个功能只需要添加地图控件.设置用户跟踪模式.在 mapView:didUpdateUserLocation: 代理方法中设置地 ...
- [iOS 利用MapKit和CoreLocation框架打造精简的定位和导航]
运行效果: 一.利用<CoreLocation/CoreLocation.h>定位 创建变量 CLLocationManager *locationManager , ...
- iOS 利用CoreLocation和MapKit开发搜索附近的商场功能
代码如下: //// SearchNearbyShopViewController.m// SearchNearbyShop//// Created by Linzhixiao on 16/2/ ...
- Corelocation及地图控件学习笔记
Corelocation基本使用 在地图章节的学习中,首先要学的便是用户位置定位,因此我们首先要掌握Corelocation的使用.(在IOS8以前可以系统会直接请求授权,现在需要我们自己调用方式通知 ...
- iOS:地图:MapKit和CoreLocation
地图:MapKit和CoreLocation 简介: 现在很多的社交软件都引入了地图和定位功能,要想实现这2大功能,那就不得不学习其中的2个框架:MaKit和CoreLocation CoreLoca ...
- CoreLocation+MapKit系统定位(含坐标以及详细地址)
iOS8 之后出现一些新的配置 [self.manager requestWhenInUseAuthorization]; 并且在info.plist文件中增加 NSLocationWhenInUse ...
- (IOS)CoreLocation 和 MapKit 的应用
CoreLocation是控制GPS硬件获取地理坐标信息的系统类库,而MapKit是系统地图的工具包,将两者结合使用可以实现不同的地图功能. 1.CoreLocation 在CoreLocation中 ...
随机推荐
- [CF 351B]Jeff and Furik[归并排序求逆序数]
题意: 两人游戏, J先走. 给出一个1~n的排列, J选择一对相邻数[题意!!~囧], 交换. F接着走, 扔一硬币, 若正面朝上, 随机选择一对降序排列的相邻数, 交换. 若反面朝上, 随机选择一 ...
- list的三种遍历方法
1.最简单的for循环遍历 for(int i = 0; i < list.size(); i++){ list.get(i); } 2.最方便的foreach循环遍 ...
- redis中各种数据类型对应的jedis操作命令
redis中各种数据类型对应的jedis操作命令 一.常用数据类型简介: redis常用五种数据类型:string,hash,list,set,zset(sorted set). 1.String类型 ...
- 用函数生成select选择框
// 生成 html select option 标签 function build_options($options, $opt='',$k='') { $frags = array(); if ( ...
- 【Android - 框架】之可悬浮列表StickyHeadersRecyclerView
这是timehop的GitHub上发表的一个控件框架,大家可以去参考它的[GitHub]. 这里先贴出GitHub上提供的效果图: 要使用这个框架,我们需要首先导入它的依赖: compile 'com ...
- Android UI学习 - GridView和ImageView的使用
GridView: A view that shows items in two-dimensional scrolling grid. The items in the grid come from ...
- ipad itunes 恢复
http://jingyan.baidu.com/article/a3aad71aa58efbb1fa00967c.html http://act.feng.com/wetools/index.php ...
- C# 里窗体里(windows form)怎么播放音乐
在.NET的winform里面,没有托管的音乐播放器,API只能播放WAV格式,对于MP3等形式的音频文件,就要依赖于 MediaPlayer里,嘿嘿 使用的方法: 在toolbox上点右键,选择“选 ...
- Const和ReadOnly
总结一下const和readonly有这么几条区别: const和readonly的值一旦初始化则都不再可以改写: const只能在声明时初始化:readonly既可以在声明时初始化也可以在构造器中初 ...
- oracle-行转列
<一>合并两个结果集,并且两个结果集的数据 根据条目自动归为一行结果集1 如下:SQL> select t1.fplx,t1.djje from yw_zjfpjl t1 ; FP ...