【高德地图API(流程法)分析】:git
前言:公司如今的网约车项目,使用的是高德地图,由于地图导航这一块的功能占比量比较大,为了方便你们对高德地图API的了解和学习使用,使用流程图把高德API分析整理了下。数组
——————————————————【一】流程:开始当前位置定位——————————————————————函数
【乘客当前位置定位涉及的API:】工具
/**学习
* @brief 单次定位。若是当前正在连续定位,调用此方法将会失败,返回NO。测试
该方法将会根据设定的 desiredAccuracy 去 获取定位信息。优化
若是获取的定位信息精确度低于 desiredAccuracy ,将会持续的等待定位信息,直到超时后经过completionBlock返回精度最高的定位信息。动画
能够经过 stopUpdatingLocation 方法去取消正在进行的单次定位请求。ui
* @param withReGeocode 是否带有逆地理信息(获取逆地理信息须要联网)编码
* @param completionBlock 单次定位完成后的Block
* @return 是否成功添加单次定位Request
*/
- (BOOL)requestLocationWithReGeocode:(BOOL)withReGeocode completionBlock:(AMapLocatingCompletionBlock)completionBlock;
/**
* @brief 连续定位回调函数.注意:若是实现了本方法,则定位信息不会经过amapLocationManager:didUpdateLocation:方法回调。
* @param manager 定位 AMapLocationManager 类。
* @param location 定位结果。
* @param reGeocode 逆地理信息。
*/
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode;
/**
* @brief 设置地图使其能够显示数组中全部的annotation, 若是数组中只有一个则直接设置地图中心为annotation的位置。
* @param annotations 须要显示的annotation
* @param animated 是否执行动画
*/
- (void)showAnnotations:(NSArray *)annotations animated:(BOOL)animated;
——————————————————————————————————————————
—————————————————【二】流程:上,下车点位置推荐——————————————————————
【定位地址搜索案例】:
AMapPOIKeywordsSearchRequest *request = [[AMapPOIKeywordsSearchRequest alloc] init];
request.keywords = keywords;
request.city = self.currentCity;
request.requireSubPOIs = YES;
request.requireExtension = YES;
request.cityLimit = YES;
request.offset = 10;
//推荐点位置搜索请求
[self.mapSearch AMapPOIKeywordsSearch:request];
/**
* @brief POI查询回调函数
* @param request 发起的请求,具体字段参考 AMapPOISearchBaseRequest 及其子类。
* @param response 响应结果,具体字段参考 AMapPOISearchResponse 。
*/
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response;
/**
* @brief POI查询回调函数
* @param request 发起的请求,具体字段参考 AMapPOISearchBaseRequest 及其子类。
* @param response 响应结果,具体字段参考 AMapPOISearchResponse 。
*/
- (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response;
—————————————————————————————————————————
——————————————————【三】流程:驾车路径规划_之_查询———————————————————————
【案例】:
self.driveAllLine = [[AMapDrivingRouteSearchRequest alloc] init];
self.driveAllLine.requireExtension = YES;
/* 出发点. */
self.driveAllLine.origin = [AMapGeoPoint locationWithLatitude: self.startPointAnnotation.coordinate.latitude
longitude: self.startPointAnnotation.coordinate.longitude];
/* 目的地. */
self.driveAllLine.destination = [AMapGeoPoint locationWithLatitude: self.endPointAnnotation.coordinate.latitude
longitude: self.endPointAnnotation.coordinate.longitude];
/*发起请求 */
[self.searchAPI AMapDrivingRouteSearch:self.driveAllLine];
【第一步】:
———出发点,目的地坐标点 (经度,纬度)生成API————
/**
* @brief 实例化一个AMapGeoPoint对象
* @param lat 纬度
* @param lon 经度
*/
+ (AMapGeoPoint *)locationWithLatitude:(CGFloat)lat longitude:(CGFloat)lon;
【第二步】:
———驾车路径规划查询接口API————
/**
* @brief 驾车路径规划查询接口
* @param request 查询选项。具体属性字段请参考 AMapDrivingRouteSearchRequest 类。
*/
- (void)AMapDrivingRouteSearch:(AMapDrivingRouteSearchRequest *)request;
【第三步】:
———路径规划查询回调API————
/**
* @brief 路径规划查询回调
* @param request 发起的请求,具体字段参考 AMapRouteSearchBaseRequest 及其子类。
* @param response 响应结果,具体字段参考 AMapRouteSearchResponse 。
*/
- (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response;
—————————————————————————————————————————
——————————————————【四】流程:驾车路径规划_之_显示———————————————————————
【第一步】:
———移除标注(移除小车等图标)API———
/**
* @brief 移除标注
* @param annotation 要移除的标注
*/
- (void)removeAnnotation:(id <MAAnnotation>)annotation;
【第二步】:
———移除overlay数组(路径)API————
/**
* @brief 移除一组Overlay
* @param overlays 要移除的overlay数组
*/
- (void)removeOverlays:(NSArray *)overlays;
【第三步】:
———向地图窗口添加标注API————
/**
* @brief 向地图窗口添加标注,须要实现MAMapViewDelegate的-mapView:viewForAnnotation:函数来生成标注对应的View
* @param annotation 要添加的标注
*/
- (void)addAnnotation:(id <MAAnnotation>)annotation;
【第四步】:
———生成的标注View 将要显示处理API(用于区分标注类型的特殊设置)————
* @param mapView 地图View
* @param annotation 指定的标注
* @return 生成的标注View
*/
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation;
【第五步】:
———根据交通情况的线路样式设置显示路径API————
/**
* @brief 根据overlay生成对应的Renderer
* @param mapView 地图View
* @param overlay 指定的overlay
* @return 生成的覆盖物Renderer
*/
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay;
—————————————————————————————————————————
——————————————————【五】其余API———————————————————————
/**
* @brief 位置或者设备方向更新后,会调用此函数
* @param mapView 地图View
* @param userLocation 用户定位信息(包括位置与设备方向等数据)
* @param updatingLocation 标示是不是location数据更新, YES:location数据更新 NO:heading数据更新
*/
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation;
/**
* @brief 逆地址编码查询接口
* @param request 查询选项。具体属性字段请参考 AMapReGeocodeSearchRequest 类。
*/
- (void)AMapReGoecodeSearch:(AMapReGeocodeSearchRequest *)request;
/**
* @brief 地图将要发生移动时调用此接口
* @param mapView 地图view
* @param wasUserAction 标识是不是用户动做
*/
- (void)mapView:(MAMapView *)mapView mapWillMoveByUser:(BOOL)wasUserAction;
/**
* @brief 地图移动结束后调用此接口
* @param mapView 地图view
* @param wasUserAction 标识是不是用户动做
*/
- (void)mapView:(MAMapView *)mapView mapDidMoveByUser:(BOOL)wasUserAction;
结束语:经过项目的一个流程跑下来,用到的高德API分析暂时就这些。
附加问题: 在使用高德SDK过程当中,出现一个系统很是耗电的问题,根据安卓端和iOS端经过工具测试SDK流程的耗电节点图来看,项目须要对影响耗电的模块进行优化。