高德开发者平台 有开发指南html
iOS9配置网络:git
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>api
请看这里 原文章:http://www.oschina.net/question/262659_149771?fromerr=Y0rzKueR网络
1>框架
CLLocationManager:定位管理器 协议:<CLLocationManagerdelegate> 设置代理 实现方法编码
CLLocation:位置的具体信息(经纬度 等等)spa
CLHeading:设备移动方向.net
CLRegion:一个区域(经常使用子类:CLCircularRegion:圆形 CLBeaconRegion:蓝牙)代理
[CLLocationManager locationServicesEnabled] 定位服务是否可用code
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); }];
iOS7的系统下 写完start就能够开始定位了:
[self.locationManager startUpdatingLocation];
可是在iOS以后就须要设置是否容许定位:设置完成这个以后才能够定位
requestAlwaysAuthorization:一直容许定位
requestWhenInUseAuthorization:用户容许
在添加以前须要在info.plist 文件中添加字段:NSLocationAlwaysUsageDescription (后面的字符串知识提示的时候会显示 并无什么用)
[self.locationManager requestAlwaysAuthorization];
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(0, 0, 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