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中 ...
随机推荐
- Domino - SGU 101 (欧拉路径)
题目大意:这是一个多米诺骨游戏,这个游戏的规则就是一个连着一个,现在给出 N 个多米诺,每个多米诺两边都有一个编号,相邻的多米诺的编号要一致,当然多米诺是可以翻转的(翻转就加‘-’,不翻转是‘+’), ...
- .Net设计模式_单列模式
理解 博友的经典说法:很多人排队去厕所蹲坑一样,每一次只能让一个人去蹲坑,这是一种通俗的理解. 理论上的理解则为,我们需要写一个类,这个类的作用就是控制,从而保证在整个应用程序的生命周期中,在任何时刻 ...
- cf 702B
You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that a ...
- PHP用ajia代码写三级联动下拉
下面是我做三级联动下拉的步骤以及逻辑 第一步:先做一个省市区表格 第二步:建个PHP页面显示用我是在<body>里放<div>用来接收要显示的省市区表格信息,里面嵌入jquer ...
- Qt解析XML文件(QXmlStreamReader)
(2013-08-03 10:53:53) 转载▼ 如何使用QXmlStreamReader来解析格式良好的XML,Qt的文档中指出,它是一种更快.更方便的Qt自己的SAX解析器(QXml ...
- Java设计模式03:常用设计模式之单例模式(创建型模式)
1. Java之单例模式(Singleton Pattern ) 单例模式是一种常见的设计模式,单例模式分三种:懒汉式单例.饿汉式单例.登记式单例三种. 单例模式有一下特点: 1.单例类只能有一个实 ...
- RHEL7重置root密码
一.rd.break方法 在linux16那一段的最后,空一格输入rd.break 按Ctrl+启动到单用户模式,如下: 进去后输入命令mount,发现根为/sysroot/,并且不能写,只有ro=r ...
- GitHub Desktop安装异常解决
为了更好的共同学习,共同进步,哥们推荐我使用GitHub记录自己每天的学习记录,当下很火的提供一个分布式的版本控制系统(Git)服务的网站,GitHub提供GitHub Desktop桌面程序方便协同 ...
- "_Default"同时存在于两个dll文件中的解决办法
编译器错误消息:CS0433: 类型“_Default”同时存在于“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Fi ...
- c# 左连接写法
var itemandformulas = from i in AttendanceItemList join f in AttendanceFormulaList on i.AttendanceCo ...