CoreLocation MKMapView
高德開(kāi)發(fā)者平臺(tái) 有開(kāi)發(fā)指南
iOS9配置網(wǎng)絡(luò):
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
請(qǐng)看這里? 原文章:http://www.oschina.net/question/262659_149771?fromerr=Y0rzKueR
1. GPS定位:<CoreAudioKit/CoreAudioKit.h>
1. 基本屬性:
1>
CLLocationManager:定位管理器?? 協(xié)議:<CLLocationManagerdelegate> 設(shè)置代理 實(shí)現(xiàn)方法
CLLocation:位置的具體信息(經(jīng)緯度 等等)
CLHeading:設(shè)備移動(dòng)方向
CLRegion:一個(gè)區(qū)域(常用子類:CLCircularRegion:圓形 CLBeaconRegion:藍(lán)牙)
[CLLocationManager locationServicesEnabled] 定位服務(wù)是否可用
distanceFilter:自動(dòng)過(guò)濾距離 移動(dòng)某個(gè)距離之后重新調(diào)用代理方法 更新位置
desiredAccuracy:定位的精度
self.manager.desiredAccuracy = kCLLocationAccuracyBest; // 最佳精度 self.manager.pausesLocationUpdatesAutomatically = YES; // 不需要的時(shí)候可以自動(dòng)暫停?
- (void)viewDidLoad {[super viewDidLoad];self.locationManager = [[CLLocationManager alloc] init];self.locationManager.delegate = self;// 允許定位 [self.locationManager requestAlwaysAuthorization];// 自動(dòng)過(guò)濾距離 移動(dòng)100米之后重新調(diào)用代理方法 更新位置self.locationManager.distanceFilter = 100.0; // 米為單位// iOS7的系統(tǒng)下 寫(xiě)完start就可以開(kāi)始定位了 [self.locationManager startUpdatingLocation];// 初始化地理編碼器:self.geocoder = [CLGeocoder new]; }2> CLGeocoder 地理編碼器:
創(chuàng)建:
self.geocoder = [CLGeocoder new];編碼:提供某個(gè)字符串 來(lái)定位位置:- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
[self.geocoder geocodeAddressString:self.inputLocation.text completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {// 取出一個(gè)位置信息CLPlacemark *placeMark = placemarks.lastObject;// 輸出信息NSLog(@"%lf %lf", placeMark.location.coordinate.latitude, placeMark.location.coordinate.longitude);}];反編碼:根據(jù)位置顯示該地方的名字等等
[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的系統(tǒng)下 寫(xiě)完start就可以開(kāi)始定位了:
[self.locationManager startUpdatingLocation];?
但是在iOS之后就需要設(shè)置是否允許定位:設(shè)置完成這個(gè)之后才可以定位
requestAlwaysAuthorization:一直允許定位
requestWhenInUseAuthorization:用戶允許
在添加之前需要在info.plist 文件中添加字段:NSLocationAlwaysUsageDescription? (后面的字符串知識(shí)提示的時(shí)候會(huì)顯示 并沒(méi)有什么用)
[self.locationManager requestAlwaysAuthorization];2. 地圖:<MapKit/MapKit.h>
1> iOS原生地圖:
前面帶MK的是系統(tǒng)自帶的地圖:
MKUserLocation:地圖上的大頭針 有title subtitle等屬性
MKMapView:用來(lái)顯示地圖 與視圖一樣 初始化需要確定frame 定位的時(shí)候需要用到coreLocation框架
showsUserLocation 設(shè)置為YES 允許跟蹤定位 (MKMapView的屬性)
可自定義MKAnnotation
// 創(chuàng)建比例系數(shù) 顯示在某個(gè)點(diǎn)上MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1, 0.1)) ; // 比例系數(shù)越小 放大效果越大self.mapView.region = region; // 系統(tǒng)自帶2> 高德:
多以MA開(kāi)頭的:
[_mapView setZoomLevel:16.0 animated:YES];? 設(shè)置縮放的比例
// 1. 驗(yàn)證key[MAMapServices sharedServices].apiKey = @“申請(qǐng)的key”;// 2. 初始化mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.bounds))];mapView.delegate = self;// mapView.language = MAMapLanguageEn; // 設(shè)置地圖顯示語(yǔ)言mapView.mapType = MAMapTypeStandard; // 地圖類型/*MAMapTypeSatellite:衛(wèi)星地圖MAMapTypeStandard:標(biāo)準(zhǔn)地圖*/ // mapView.showTraffic = YES; // 顯示實(shí)時(shí)交通路況 [self.view addSubview:mapView];mapView.showsUserLocation = YES;mapView的定位模式: userTrackingMode
MAUserTrackingModeNone:不跟隨用戶位置,僅在地圖上顯示。
MAUserTrackingModeFollow:跟隨用戶位置移動(dòng),并將定位點(diǎn)設(shè)置成地圖中心點(diǎn)
MAUserTrackingModeFollowWithHeading:跟隨用戶的位置和角度移動(dòng)
系統(tǒng)的地圖和 高德地圖 的區(qū)別:http://www.mamicode.com/info-detail-573898.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/Evelyn-zn/p/4979101.html
總結(jié)
以上是生活随笔為你收集整理的CoreLocation MKMapView的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java基础07 包
- 下一篇: IBatis.net动态SQL语句