iOS 地图线路动态可视化显示
2014-11-04 16:42
295 查看
之前有碰到过这样的问题,就是画出两点之间的距离,然后将线路显示在可视化的范围内,下面是一些主要代码:
#pragma mark - 驾车线路检索 - (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error { if (error == BMK_SEARCH_NO_ERROR) { //在此处理正常结果 NSArray* array = [NSArray arrayWithArray:_mapView.annotations]; [_mapView removeAnnotations:array]; array = [NSArray arrayWithArray:_mapView.overlays]; [_mapView removeOverlays:array]; if (error == BMK_SEARCH_NO_ERROR) { BMKDrivingRouteLine* plan = (BMKDrivingRouteLine*)[result.routes objectAtIndex:0]; // 计算路线方案中的路段数目 int size = [plan.steps count]; int planPointCounts = 0; for (int i = 0; i < size; i++) { BMKDrivingStep* transitStep = [plan.steps objectAtIndex:i]; if(i==0){ RouteAnnotation* item = [[RouteAnnotation alloc]init]; item.coordinate = plan.starting.location; item.title = @"起点"; item.type = 0; [_mapView addAnnotation:item]; // 添加起点标注 }else if(i==size-1){ RouteAnnotation* item = [[RouteAnnotation alloc]init]; item.coordinate = plan.terminal.location; item.title = @"终点"; item.type = 1; [_mapView addAnnotation:item]; // 添加起点标注 } //添加annotation节点 RouteAnnotation* item = [[RouteAnnotation alloc]init]; item.coordinate = transitStep.entrace.location; item.title = transitStep.entraceInstruction; item.degree = transitStep.direction * 30; item.type = 4; [_mapView addAnnotation:item]; //轨迹点总数累计 planPointCounts += transitStep.pointsCount; //----------------------------------------------------------- if (i==0) { //以第一个坐标点做初始值 minLat = plan.starting.location.latitude; maxLat = plan.starting.location.latitude; minLon = plan.starting.location.longitude; maxLon = plan.starting.location.longitude; }else{ //对比筛选出最小纬度,最大纬度;最小经度,最大经度 minLat = MIN(minLat, transitStep.entrace.location.latitude); maxLat = MAX(maxLat, transitStep.entrace.location.latitude); minLon = MIN(minLon, transitStep.entrace.location.longitude); maxLon = MAX(maxLon, transitStep.entrace.location.longitude); } //----------------------------------------------------------- } [self setVisibleRegin]; // 添加途经点 if (plan.wayPoints) { for (BMKPlanNode* tempNode in plan.wayPoints) { RouteAnnotation* item = [[RouteAnnotation alloc]init]; item = [[RouteAnnotation alloc]init]; item.coordinate = tempNode.pt; item.type = 5; item.title = tempNode.name; [_mapView addAnnotation:item]; } } //轨迹点 BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts]; int i = 0; for (int j = 0; j < size; j++) { BMKDrivingStep* transitStep = [plan.steps objectAtIndex:j]; int k=0; for(k=0;k<transitStep.pointsCount;k++) { temppoints[i].x = transitStep.points[k].x; temppoints[i].y = transitStep.points[k].y; i++; } } // 通过points构建BMKPolyline BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts]; [_mapView addOverlay:polyLine]; // 添加路线overlay delete []temppoints; } } else { NSLog(@"抱歉,未找到结果"); } }
- (void)setVisibleRegin { //计算中心点 CLLocationCoordinate2D centCoor; centCoor.latitude = (CLLocationDegrees)((maxLat+minLat) * 0.5f); centCoor.longitude = (CLLocationDegrees)((maxLon+minLon) * 0.5f); BMKCoordinateSpan span; //计算地理位置的跨度 span.latitudeDelta = maxLat - minLat; span.longitudeDelta = maxLon - minLon; //得出数据的坐标区域 BMKCoordinateRegion region = BMKCoordinateRegionMake(centCoor, span); //百度地图的坐标范围转换成相对视图的位置 CGRect fitRect = [_mapView convertRegion:region toRectToView:_mapView]; //将地图视图的位置转换成地图的位置, BMKMapRect fitMapRect = [_mapView convertRect:fitRect toMapRectFromView:_mapView]; //设置地图可视范围为数据所在的地图位置 [_mapView setVisibleMapRect:fitMapRect animated:YES]; }欢迎大家批评指正!!!
相关文章推荐
- ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(四)--动态绘制点
- 招聘信息显示苹果开发iOS地图应用
- 在ios中使用手机定位获得的经纬度坐标 通过 arcgis的api 显示在wgs84 坐标系的地图上。
- ios中用三种方式显示gif动态图片
- ios 地图大头针自定义显示图…
- ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(二)--Silverlight 配置动态的 webService、动态加载ArcGis地图服务
- 如何在iOS地图上高效的显示大量数据 分类: iOS开发
- ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(四)--动态绘制点
- 如何在iOS地图上高效的显示大量数据
- iOS定位服务与地图开发(4)---显示地图
- ios通过google map显示地图和乘车信息
- 图吧地图:①得到地图上某个位置的经纬度;②显示多个坐标点;③动态显示多个坐标点;
- IOS开发之---地图显示
- [ios3-地图] 如何在iOS地图上高效的显示大量数据 [转]
- ArcGis For Silverlight API,地图显示Gis,绘制点,线,绘制图等(四)--动态绘制点
- iOS版MapABC的简单显示地图的Demo
- iOS地图的大头针的标题和子标题自动显示
- ios 地图大头针自定义显示图片 MKAnnotationView
- iOS 输入地点 显示当前位置地图并用大头针标注