iOS 百度地图 轨迹记录 道路贴合

最近在做一个小的demo,试一下轨迹记录。

记录轨迹需要不停的获取位置记录到数据库。

在画折现的时候会在道路拐角处直接连线,不会与道路贴合,在这说一下我的解决方案。

我调用了百度地图的路径规划api。这样就能实现路径贴合功能了。

在此附上dome:点击打开链接

强调:这个dome是真机上运行,在模拟器上会报错。下载的时候注意一下。

由于各种原因图片是用手机拍的。

上张图看看:

核心代码:

调用驾车线路规划,规划出从这点到那点的线路然后画出路线,生成的线路在下面函数中获得。

– (void)onGetDrivingRouteResult:(BMKRouteSearch *)searcher result:(BMKDrivingRouteResult *)result errorCode:(BMKSearchErrorCode)error上面这是代理方法。

BMKPlanNode *startNode = [[BMKPlanNode alloc]init];CLLocationCoordinate2D startCoordinate;startCoordinate.latitude =36.727558;startCoordinate.longitude =119.185956;startNode.pt = startCoordinate;BMKPlanNode *endNode = [[BMKPlanNode alloc]init];CLLocationCoordinate2D endCoordnate;endCoordnate.latitude =36.827558;endCoordnate.longitude =119.385956;endNode.pt = endCoordnate;BMKDrivingRoutePlanOption * drivingRoutePlanOption = [[BMKDrivingRoutePlanOption alloc]init];drivingRoutePlanOption.from = startNode;drivingRoutePlanOption.to = endNode;if ([_searcher drivingSearch:drivingRoutePlanOption]) {NSLog(@"路线查找成功");}- (void)onGetDrivingRouteResult:(BMKRouteSearch *)searcher result:(BMKDrivingRouteResult *)result errorCode:(BMKSearchErrorCode)error{BMKDrivingRouteLine *plan = (BMKDrivingRouteLine *)[result.routes objectAtIndex:0];int size = (int)[plan.steps count];int pointCount = 0;for (int i = 0; i< size; i++) {BMKDrivingStep *step = [plan.steps objectAtIndex:i];pointCount += step.pointsCount;}BMKMapPoint *points = new BMKMapPoint[pointCount];int k = 0;for (int i = 0; i< size; i++) {BMKDrivingStep *step = [plan.steps objectAtIndex:i];for (int j= 0; j<step.pointsCount; j++) {points[k].x = step.points[j].x;points[k].y = step.points[j].y;k++;}}NSLog(@"点的个数:(%d)",k);BMKPolyline *polyLine = [BMKPolyline polylineWithPoints:points count:pointCount];[_mapView addOverlay:polyLine];}在上面方法中我们从返回的线路中 获取该线路的路段,再从路段中获取到路段中的点,,最后对这些点进行画线。

可就是这样,还是有人,期望过多的温暖。

iOS 百度地图 轨迹记录 道路贴合

相关文章:

你感兴趣的文章:

标签云: