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中 ...
随机推荐
- 【Android - 进阶】之MultiDex的配置
一.什么是MultiDex 随着时代的进步,人们对手机 APP 的需求越来越大,越来越苛刻,很多APP都变得很大,再加上APP都不可避免的需要导入一些框架.第三方类库等等,就更加大了项目的整体文件体系 ...
- Quartz.Net任务调度框架
Quartz.Net是一个开源的任务调度框架,非常强大,能够通过简单的配置帮助我们定时具体的操作. 相对于我们用的线程里面while(true)然后sleep来执行某个操作,应该算的上是高端,大气,上 ...
- Android教程:ImageView 设置图片
Android doc中是这样描述的: public void setImageResource (int resId) 这是其中的一个方法,参数resld是这样: ImageView.setImag ...
- C# 保存窗口为图片(保存纵断面图)
源代码例如以下: #region 保存纵断面截图 private void button_save_Click(object sender , EventArgs e) { SaveFileDialo ...
- [Reactive Programming] RxJS dynamic behavior
This lesson helps you think in Reactive programming by explaining why it is a beneficial paradigm fo ...
- java Permissions and Security Policy--官方文档
3 Permissions and Security Policy 3.1 The Permission Classes The permission classes represent access ...
- 查看pid
可以使用ps -ef | grep httpd查看PID 然后kill –l PID
- Windows 8和CentOS 6.4(64)双系统硬盘安装教程
最近在笔记本上升级原来的系统Win7到Win8,同时又安装了CentOS 6.4(64)系统,实现双系统共存.着实折腾了一番,主要是CentOS6.4(64)的两个iso文件加起来5G多(其实只用第一 ...
- jdk配置及maven配置
jdk配置及maven配置 >>>>>>>>>>>>>>>>>>>>>&g ...
- Rouh set 入门知识3(上下近似集,正负域,边界域)
在RS中,引入两个概念:一个是下近似集,另一个是上近似集.下近似集是指当一个集合不能利用有效的等价关系被恰当的分类是时,则可通过另外的集合来达到这个集合的近似.形式上,设X⊆U是任一子集,R是U上的等 ...