ios 点生成线路 百度地图_iOS百度地图开发之路径规划

本文介绍如何在iOS应用中使用百度地图SDK进行路径规划。首先初始化BMKMapView并设置代理,然后创建路线搜索实例并设置其代理。接着展示起点和终点的标注,并根据BMKDrivingRouteLine绘制路线。最后实现缩放按钮、返回按钮和导航按钮的功能。
摘要由CSDN通过智能技术生成

路线规划

使用百度地图SDK版本为2.9.1。

需要将改

代码:

#import

#import

#import

#import

#import

#import

#import "HXRouteViewController.h"

#import "UIView+Extension.h"

#import "HXAnnotationView.h"

#import "HXAnnotation.h"

#import "HXMenDDetail.h"

#import "UIImage+Rotate.h"

#import "UIColor+HexString.h"

#import "FMActionSheet.h"

#import "ZoomInOrOutButton.h"

#define MYBUNDLE_NAME @ "mapapi.bundle"

#define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: MYBUNDLE_NAME]

#define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH]

/**

* 路线的标注

*/

@interface RouteAnnotation : BMKPointAnnotation

{

int _type; ///<0:起点 1:终点 2:公交 3:地铁 4:驾乘 5:途经点

int _degree;

}

@property (nonatomic) int type;

@property (nonatomic) int degree;

@end

@implementation RouteAnnotation

@synthesize type = _type;

@synthesize degree = _degree;

@end

@interface HXRouteViewController (){

BMKMapView *_mapView;

NSString *_cityName;

BMKRouteSearch *_routesearch;

}

/**

* 返回按钮

*/

//@property (nonatomic , weak)UIButton *preBtn;

/**

* 存放标注数组

*/

@property(nonatomic , strong) NSMutableArray *annotations;

/**

* 用户当前位置

*/

@property(nonatomic , strong) BMKUserLocation *userLocation;

@property(nonatomic , strong) HXAnnotation *anno;

@end

@implementation HXRouteViewController

- (NSString*)getMyBundlePath1:(NSString *)filename

{

NSBundle * libBundle = MYBUNDLE ;

if ( libBundle && filename ){

NSString * s=[[libBundle resourcePath ] stringByAppendingPathComponent:filename];

return s;

}

return nil ;

}

- (void)viewDidLoad

{

[super viewDidLoad];

UIView *statusView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENW, 20)];

statusView.backgroundColor = [UIColor colorWithR:46 G:139 B:84 alpha:1.];

[self.view addSubview:statusView];

_routesearch = [[BMKRouteSearch alloc] init];

_routesearch.delegate = self;

//初始化BMKMapView并设置代理

_mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 20, SCREENW, SCREENH - 140)];

[self.view addSubview:_mapView];

_mapView.delegate = self;

_mapView.buildingsEnabled = YES;

_mapView.overlookEnabled = YES;

_mapView.showMapScaleBar = YES;

_mapView.overlooking = -45;

//设置放大/缩小按钮

[self setupNavButton];

//返回按钮

[self backButton];

//设置导航按钮

// [self setupNavButton];

//驾车路线

[self showDriveSearch];

//设置放大/缩小按钮

[self setupZoomButton];

}

#pragma mark 设置放大/缩小按钮

-(void)setupZoomButton{

ZoomInOrOutButton *zoomInOrOutBtn = [[[NSBundle mainBundle] loadNibNamed:@"ZoomInOrOutButton" owner:nil options:nil] lastObject];

zoomInOrOutBtn.layer.cornerRadius =

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值