重要的寫在前面庶橱,整理了一下系統(tǒng)高德地圖的一般使用贮勃,相關(guān)的demo請(qǐng)點(diǎn)擊demo鏈接 ,已經(jīng)更新了Swift版本。
1. 地圖(MKMapView)的使用
self.mapView.mapType =? MKMapTypeStandard;
//顯示指南針
self.mapView.showsCompass = YES;
//顯示比例尺
self.mapView.showsScale = YES;
//顯示用戶所在的位置
self.mapView.showsUserLocation = YES;
self.mapView.delegate =self;
[self.view addSubview:self.mapView];
#pragma mark -? 地圖代理方法有
//一個(gè)位置更改默認(rèn)只會(huì)調(diào)用一次苏章,不斷監(jiān)測(cè)用戶的當(dāng)前位置//每次調(diào)用寂嘉,都會(huì)把用戶的最新位置(userLocation參數(shù))傳進(jìn)來
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
}
//地圖的顯示區(qū)域即將發(fā)生改變的時(shí)候調(diào)用
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{? ? }
//地圖的顯示區(qū)域已經(jīng)發(fā)生改變的時(shí)候調(diào)用
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{? ? }//設(shè)置大頭針- (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
}
2. 定位(CLLocationManager)的使用
if ( [CLLocationManager? locationServicesEnabled]) {
NSLog(@"可以定位");
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
//設(shè)置定位精度
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//設(shè)置距離
self.locationManager.distanceFilter = 50;
//申請(qǐng)定位許可,iOS8以后特有
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
//開始定位
[self.locationManager startUpdatingLocation];
}else{
NSLog(@"請(qǐng)打開定位權(quán)限");
}
#pragma mark - 定位代理方法//locationManager:didUpdateLocations:(調(diào)用很頻繁)- (void)locationManager:(CLLocationManager *)manager? ? didUpdateLocations:(NSArray*)locations{
}
//定位失敗
- (void)locationManager:(CLLocationManager *)manager? didFailWithError:(NSError *)error{
?? NSLog(@"定位失敗error%@",error);
}
//方向的更新
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
}
//用于判斷是否顯示方向的校對(duì),用于判斷是否顯示方向的校對(duì),返回yes的時(shí)候枫绅,將會(huì)校對(duì)正確之后才會(huì)停止
//或者dismissheadingcalibrationdisplay方法解除泉孩。
-(BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager{
return? YES;
}
3.自定義大頭針
4.路線規(guī)劃,畫線
5.跳轉(zhuǎn)第三方地圖導(dǎo)航
需要注意要添加白名單