iOS系统高德地图的使用

来源:互联网 发布:八个字网络流行语 编辑:程序博客网 时间:2024/05/16 05:40

重要的写在前面,整理了一下系统高德地图的一般使用,相关demo请点击demo链接 ,已经更新了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 -  地图代理方法有//一个位置更改默认只会调用一次,不断监测用户的当前位置//每次调用,都会把用户的最新位置(userLocation参数)传进来- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{}//地图的显示区域即将发生改变的时候调用- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{    }//地图的显示区域已经发生改变的时候调用- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{    }//设置大头针- (nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{}

2. 定位(CLLocationManager)的使用

if ( [CLLocationManager  locationServicesEnabled]) {NSLog(@"可以定位");self.locationManager = [[CLLocationManager alloc]init];self.locationManager.delegate = self;//设置定位精度self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;//设置距离self.locationManager.distanceFilter = 50;//申请定位许可,iOS8以后特有if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {[self.locationManager requestWhenInUseAuthorization];}//开始定位[self.locationManager startUpdatingLocation];}else{NSLog(@"请打开定位权限");}#pragma mark - 定位代理方法//locationManager:didUpdateLocations:(调用很频繁)- (void)locationManager:(CLLocationManager *)manager    didUpdateLocations:(NSArray*)locations{}//定位失败- (void)locationManager:(CLLocationManager *)manager  didFailWithError:(NSError *)error{   NSLog(@"定位失败error%@",error);}//方向的更新- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{}//用于判断是否显示方向的校对,用于判断是否显示方向的校对,返回yes的时候,将会校对正确之后才会停止//或者dismissheadingcalibrationdisplay方法解除。-(BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager{return  YES;}

3.自定义大头针
这里写图片描述

4.路线规划,画线
这里写图片描述

5.跳转第三方地图导航

需要注意要添加白名单这里写图片描述

6. 地理编码和反地理编码(CLGeocoder)的使用

原创粉丝点击