iOS集成百度地图方法步骤
前言:app中的导航功能越来越流行,现在我自己做的项目中也有此需求,做过了后记录下笔记。 由于源代码保密所以这里仅仅提供demo,下面是效果图
一:iOS地图SDK
1.打开 百度地图api链接
2.注册成为开发者并按照步骤走
3.遇到的问题解决
4.遇到这种错误
2016-03-22 17:11:09.745 baiduMap[6664:276199] 地图所需资源文件不完整,请根据开发指南正确添加mapapi.bundle文件
成功:
4.注意BMKMapView 的类型
///地图View类,使用此View可以显示地图窗口,并且对地图进行相关的操作
@interface BMKMapView :UIView
5.集成基础地图
效果:
6.poi检索
遇到错误时候的处理方法点击错误码进去看看
可以用%zd把错误代码打印出来
- //检索结果状态码
- typedef enum{
- BMK_SEARCH_NO_ERROR = 0,///<检索结果正常返回
- BMK_SEARCH_AMBIGUOUS_KEYWORD,///<检索词有岐义
- BMK_SEARCH_AMBIGUOUS_ROURE_ADDR,///<检索地址有岐义
- BMK_SEARCH_NOT_SUPPORT_BUS,///<该城市不支持公交搜索
- BMK_SEARCH_NOT_SUPPORT_BUS_2CITY,///<不支持跨城市公交
- BMK_SEARCH_RESULT_NOT_FOUND,///<没有找到检索结果
- BMK_SEARCH_ST_EN_TOO_NEAR,///<起终点太近
- BMK_SEARCH_KEY_ERROR,///<key错误
- BMK_SEARCH_NETWOKR_ERROR,///网络连接错误
- BMK_SEARCH_NETWOKR_TIMEOUT,///网络连接超时
- BMK_SEARCH_PERMISSION_UNFINISHED,///还未完成鉴权,请在鉴权通过后重试
- }BMKSearchErrorCode;
检索成功代码:
- #import "ViewController.h"
- #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
- #import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
- @interface ViewController ()<BMKMapViewDelegate,BMKPoiSearchDelegate>
- @property (weak, nonatomic) IBOutlet BMKMapView *mapView;
- //@property(strong,nonatomic)BMKMapView *mapView;
- @property (nonatomic, strong) BMKPoiSearch *search;
- @end
- @implementation ViewController
- #pragma mark poi搜索
- - (BMKPoiSearch *)search
- {
- if (!_search) {
- _search = [[BMKPoiSearch alloc]init];
- _search.delegate = self;
- }
- return _search;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- // self.view = mapView;
- self.mapView.delegate = self;
- // 添加一个PointAnnotation
- // BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- // CLLocationCoordinate2D coor;
- // coor.latitude = 39.915;
- // coor.longitude = 116.404;
- // annotation.coordinate = coor;
- // annotation.title = @"这里是China";
- // annotation.subtitle = @"这是中国";
- // [_mapView addAnnotation:annotation];
- //发起检索
- BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
- option.pageIndex = 0;
- option.pageCapacity = 10;
- // option.location = (CLLocationCoordinate2D){39.915, 116.404};//北京
- option.location = (CLLocationCoordinate2D){23.117055, 113.275995};//广州
- option.keyword = @"小吃";
- BOOL flag = [self.search poiSearchNearBy:option];
- if(flag)
- {
- NSLog(@"周边检索发送成功");
- }
- else
- {
- NSLog(@"周边检索发送失败");
- }
- }
- #pragma mark BMKMapViewDelegate
- - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
- newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
- newAnnotationView.animatesDrop = YES; //设置该标注点动画显示
- return newAnnotationView;
- }
- return nil;
- }
- #pragma mark BMKPoiSearchDelegate
- - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
- {
- if (error == BMK_SEARCH_NO_ERROR) {
- //在此处理正常结果
- // NSLog(@"%@", poiResultList.poiInfoList);
- [poiResultList.poiInfoList enumerateObjectsUsingBlock:^(BMKPoiInfo * _Nonnull obj, NSUInteger idx, BOOLBOOL * _Nonnull stop) {
- NSLog(@"obj.pt = %@,obj.name = %@,obj.address = %@", obj.pt,obj.name,obj.address);
- // [self addAnnoWithPT:obj.pt andTitle:obj.name andAddress:obj.address];
- }];
- }
- else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
- //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
- // result.cityList;
- NSLog(@"起始点有歧义");
- } else {
- NSLog(@"抱歉,未找到结果--%zd", error);
- }
- }
- @end
将检索结果以大头针展示出来 代码
- #import "ViewController.h"
- #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
- #import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
- @interface ViewController ()<BMKMapViewDelegate,BMKPoiSearchDelegate>
- @property (weak, nonatomic) IBOutlet BMKMapView *mapView;
- //@property(strong,nonatomic)BMKMapView *mapView;
- @property (nonatomic, strong) BMKPoiSearch *search;
- @end
- @implementation ViewController
- #pragma mark poi搜索
- - (BMKPoiSearch *)search
- {
- if (!_search) {
- _search = [[BMKPoiSearch alloc]init];
- _search.delegate = self;
- }
- return _search;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- // self.view = mapView;
- self.mapView.delegate = self;
- // 添加一个PointAnnotation
- // BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- // CLLocationCoordinate2D coor;
- // coor.latitude = 39.915;
- // coor.longitude = 116.404;
- // annotation.coordinate = coor;
- // annotation.title = @"这里是China";
- // annotation.subtitle = @"这是中国";
- // [_mapView addAnnotation:annotation];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- //发起检索
- BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
- option.pageIndex = 0;
- option.pageCapacity = 10;
- option.location = (CLLocationCoordinate2D){39.915, 116.404};//北京
- // option.location = (CLLocationCoordinate2D){23.117055, 113.275995};//广州
- option.keyword = @"大学";
- BOOL flag = [self.search poiSearchNearBy:option];
- if(flag)
- {
- NSLog(@"周边检索发送成功");
- }
- else
- {
- NSLog(@"周边检索发送失败");
- }
- }
- #pragma mark BMKMapViewDelegate
- - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
- newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
- newAnnotationView.animatesDrop = YES; //设置该标注点动画显示
- return newAnnotationView;
- }
- return nil;
- }
- #pragma mark BMKPoiSearchDelegate 处理POI检索结果
- - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
- {
- if (error == BMK_SEARCH_NO_ERROR) {
- //在此处理正常结果
- // NSLog(@"%@", poiResultList.poiInfoList);
- [poiResultList.poiInfoList enumerateObjectsUsingBlock:^(BMKPoiInfo * _Nonnull obj, NSUInteger idx, BOOLBOOL * _Nonnull stop) {
- NSLog(@"obj.pt = %@,obj.name = %@,obj.address = %@", obj.pt,obj.name,obj.address);
- [self addAnnoWithPT:obj.pt andTitle:obj.name andAddress:obj.address];
- }];
- }
- else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
- //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
- // result.cityList;
- NSLog(@"起始点有歧义");
- } else {
- NSLog(@"抱歉,未找到结果--%zd", error);
- }
- }
- #pragma mark 检索成功添加大头针
- - (void)addAnnoWithPT:(CLLocationCoordinate2D)coor andTitle:(NSString *)title andAddress:(NSString *)address
- {
- BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = coor;
- annotation.title = title;
- annotation.subtitle = address;
- [self.mapView addAnnotation:annotation];
- }
- @end
结果:
用这个方法将长按的地方作为要检索的区域
-(void)mapview:(BMKMapView *)mapView onLongClick:(CLLocationCoordinate2D)coordinate
代码:
- #import "ViewController.h"
- #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
- #import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
- @interface ViewController ()<BMKMapViewDelegate,BMKPoiSearchDelegate>
- @property (weak, nonatomic) IBOutlet BMKMapView *mapView;
- //@property(strong,nonatomic)BMKMapView *mapView;
- @property (nonatomic, strong) BMKPoiSearch *search;
- @end
- @implementation ViewController
- #pragma mark poi搜索
- - (BMKPoiSearch *)search
- {
- if (!_search) {
- _search = [[BMKPoiSearch alloc]init];
- _search.delegate = self;
- }
- return _search;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- // self.view = mapView;
- self.mapView.delegate = self;
- // 添加一个PointAnnotation
- // BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- // CLLocationCoordinate2D coor;
- // coor.latitude = 39.915;
- // coor.longitude = 116.404;
- // annotation.coordinate = coor;
- // annotation.title = @"这里是China";
- // annotation.subtitle = @"这是中国";
- // [_mapView addAnnotation:annotation];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- //发起检索
- // BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
- // option.pageIndex = 0;
- // option.pageCapacity = 10;
- //// option.location = (CLLocationCoordinate2D){39.915, 116.404};//北京
- //
- //
- // option.location = (CLLocationCoordinate2D){23.117055, 113.275995};//广州
- //// option.keyword = @"大学"; //北京检索大学
- // option.keyword = @"小吃"; //广州检索小吃
- // BOOL flag = [self.search poiSearchNearBy:option];
- // if(flag)
- // {
- // NSLog(@"周边检索发送成功");
- // }
- // else
- // {
- // NSLog(@"周边检索发送失败");
- // }
- [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(23.132931, 113.375924)]; //将地图自动定位到检索到的区域
- }
- #pragma mark 在此方法中打印定位的经纬度跨度
- -(void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
- {
- NSLog(@"%f---%f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);
- }
- #pragma mark BMKMapViewDelegate
- - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]){
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
- newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
- newAnnotationView.animatesDrop = YES; //设置该标注点动画显示
- return newAnnotationView;
- }
- return nil;
- }
- #pragma mark BMKPoiSearchDelegate 处理POI检索结果
- - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
- {
- if (error == BMK_SEARCH_NO_ERROR) {
- //在此处理正常结果
- // NSLog(@"%@", poiResultList.poiInfoList);
- [poiResultList.poiInfoList enumerateObjectsUsingBlock:^(BMKPoiInfo * _Nonnull obj, NSUInteger idx, BOOLBOOL * _Nonnull stop) {
- NSLog(@"obj.pt = %@,obj.name = %@,obj.address = %@", obj.pt,obj.name,obj.address);
- [self addAnnoWithPT:obj.pt andTitle:obj.name andAddress:obj.address];
- }];
- }
- else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
- //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
- // result.cityList;
- NSLog(@"起始点有歧义");
- } else {
- NSLog(@"抱歉,未找到结果--%zd", error);
- }
- }
- #pragma mark 检索成功添加大头针
- - (void)addAnnoWithPT:(CLLocationCoordinate2D)coor andTitle:(NSString *)title andAddress:(NSString *)address
- {
- BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = coor;
- annotation.title = title;
- annotation.subtitle = address;
- [self.mapView addAnnotation:annotation];
- }
- #pragma mark 将长按的地方作为要检索的区域
- -(void)mapview:(BMKMapView *)mapView onLongClick:(CLLocationCoordinate2D)coordinate
- {
- BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
- option.pageIndex = 0;
- option.pageCapacity = 30;
- option.location = coordinate;
- option.keyword = @"大学";
- BOOL flag = [self.search poiSearchNearBy:option];
- if(flag)
- {
- NSLog(@"周边检索发送成功");
- }
- else
- {
- NSLog(@"周边检索发送失败");
- }
- // CLLocationCoordinate2D center = option.location;
- // BMKCoordinateSpan span = BMKCoordinateSpanMake(0.021686, 0.014705);
- // BMKCoordinateRegion region = BMKCoordinateRegionMake(center, span);
- // [self.mapView setRegion:region animated:YES];
- [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; //将地图自动定位到检索到的区域
- }
- @end
效果:
二:iOS导航SDK
1.打开链接
2.按照上面给出的步骤配置好
效果:
代码:
- //
- // ViewController.m
- // baiduMap
- //
- // Created by Vitco on 16/3/22.
- // Copyright © 2016年 Vitco. All rights reserved.
- //
- #import "ViewController.h"
- #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
- #import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
- #import "BNCoreServices.h"
- @interface ViewController ()<BMKMapViewDelegate,BMKPoiSearchDelegate,BNNaviRoutePlanDelegate>
- @property (weak, nonatomic) IBOutlet BMKMapView *mapView;
- //@property(strong,nonatomic)BMKMapView *mapView;
- @property (nonatomic, strong) BMKPoiSearch *search;
- @end
- @implementation ViewController
- #pragma mark poi搜索
- - (BMKPoiSearch *)search
- {
- if (!_search) {
- _search = [[BMKPoiSearch alloc]init];
- _search.delegate = self;
- }
- return _search;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // BMKMapView* mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
- // self.view = mapView;
- self.mapView.delegate = self;
- // 添加一个PointAnnotation
- // BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- // CLLocationCoordinate2D coor;
- // coor.latitude = 39.915;
- // coor.longitude = 116.404;
- // annotation.coordinate = coor;
- // annotation.title = @"这里是China";
- // annotation.subtitle = @"这是中国";
- // [_mapView addAnnotation:annotation];
- }
- #pragma mark 发起导航 路线规划
- //- (void)startNaviWithEndPT:(CLLocationCoordinate2D)endPT
- //{
- // //节点数组
- // NSMutableArray *nodesArray = [[NSMutableArray alloc] initWithCapacity:2];
- //
- // //起点
- // BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
- // startNode.pos = [[BNPosition alloc] init];
- // startNode.pos.x = 113.375924;
- // startNode.pos.y = 23.132931;
- // startNode.pos.eType = BNCoordinate_BaiduMapSDK;
- // [nodesArray addObject:startNode];
- //
- // //终点
- // BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
- // endNode.pos = [[BNPosition alloc] init];
- // endNode.pos.x = endPT.longitude;
- // endNode.pos.y = endPT.latitude;
- // endNode.pos.eType = BNCoordinate_BaiduMapSDK;
- // [nodesArray addObject:endNode];
- // //发起路径规划
- // [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
- //}
- //发起导航
- - (void)startNavi
- {
- //节点数组
- NSMutableArray *nodesArray = [[NSMutableArray alloc] initWithCapacity:2];
- //起点
- BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
- startNode.pos = [[BNPosition alloc] init];
- startNode.pos.x = 113.936392;
- startNode.pos.y = 22.547058;
- startNode.pos.eType = BNCoordinate_BaiduMapSDK;
- [nodesArray addObject:startNode];
- //终点
- BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
- endNode.pos = [[BNPosition alloc] init];
- endNode.pos.x = 114.077075;
- endNode.pos.y = 22.543634;
- endNode.pos.eType = BNCoordinate_BaiduMapSDK;
- [nodesArray addObject:endNode];
- //发起路径规划
- [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
- }
- //导航算路成功后,在回调函数中发起导航,如下:
- //算路成功回调
- -(void)routePlanDidFinished:(NSDictionary *)userInfo
- {
- NSLog(@"算路成功");
- //路径规划成功,开始导航
- // [BNCoreServices_UI showNaviUI: BN_NaviTypeReal delegete:self isNeedLandscape:YES];
- [BNCoreServices_UI showNaviUI: BN_NaviTypeReal delegete:nil isNeedLandscape:YES];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self startNavi];
- [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(23.132931, 113.375924)]; //将地图自动定位到检索到的区域
- }
- #pragma mark 2.在此方法中打印定位的经纬度跨度
- -(void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
- {
- NSLog(@"%f---%f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);
- }
- #pragma mark 3:根据anntation生成对应的View
- /**
- *根据anntation生成对应的View
- *@param mapView 地图View
- *@param annotation 指定的标注
- *@return 生成的标注View
- */
- - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- static NSString *pinID = @"PIN";
- BMKPinAnnotationView *newAnnotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
- if (newAnnotationView == nil) {
- newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID];
- }
- newAnnotationView.annotation = annotation; //重用赋值
- newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
- newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
- //在大头针上面添加一个按钮 增添一个点击事件 当响应这个事件的时候就做一些事情(在这里可以是导航)
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
- [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
- newAnnotationView.rightCalloutAccessoryView = btn;
- return newAnnotationView;
- }
- return nil;
- }
- - (void)click
- {
- NSLog(@"开始导航");
- // CLLocationCoordinate2D coordinate = _selectAnno.coordinate;
- // [self startNaviWithEndPT:coordinate];
- }
- #pragma mark BMKPoiSearchDelegate 4.处理POI检索结果
- - (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
- {
- if (error == BMK_SEARCH_NO_ERROR) {
- //在此处理正常结果
- // NSLog(@"%@", poiResultList.poiInfoList);
- [poiResultList.poiInfoList enumerateObjectsUsingBlock:^(BMKPoiInfo * _Nonnull obj, NSUInteger idx, BOOLBOOL * _Nonnull stop) {
- NSLog(@"obj.pt = %@,obj.name = %@,obj.address = %@", obj.pt,obj.name,obj.address);
- [self addAnnoWithPT:obj.pt andTitle:obj.name andAddress:obj.address];
- }];
- }
- else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
- //当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
- // result.cityList;
- NSLog(@"起始点有歧义");
- } else {
- NSLog(@"抱歉,未找到结果--%zd", error);
- }
- }
- #pragma mark 检索成功添加大头针
- - (void)addAnnoWithPT:(CLLocationCoordinate2D)coor andTitle:(NSString *)title andAddress:(NSString *)address
- {
- BMKPointAnnotation * annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = coor;
- annotation.title = title;
- annotation.subtitle = address;
- [self.mapView addAnnotation:annotation];
- }
- #pragma mark 1. 将长按的地方作为要检索的区域
- -(void)mapview:(BMKMapView *)mapView onLongClick:(CLLocationCoordinate2D)coordinate
- {
- BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
- option.pageIndex = 0;
- option.pageCapacity = 30;
- option.location = coordinate;
- option.keyword = @"大学";
- BOOL flag = [self.search poiSearchNearBy:option];
- if(flag)
- {
- NSLog(@"周边检索发送成功");
- }
- else
- {
- NSLog(@"周边检索发送失败");
- }
- // CLLocationCoordinate2D center = option.location;
- // BMKCoordinateSpan span = BMKCoordinateSpanMake(0.021686, 0.014705);
- // BMKCoordinateRegion region = BMKCoordinateRegionMake(center, span);
- // [self.mapView setRegion:region animated:YES];
- [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; //将地图自动定位到检索到的区域
- }
- @end
模拟导航效果:
语音播报:
iOS集成百度地图方法步骤的更多相关文章
- iOS 集成百度地图 位置偏移问题
iOS 集成百度SDK 请参考 百度地图官方文档 ,这里不就多啰嗦了 本文介绍的是在百度地图上根据经纬度,自定义气泡时,气泡位置的偏移,在我们天朝这种事是很常见的,也见怪不怪了,在项目中使用的百度地图 ...
- IOS 集成百度地图
申请key ● http://lbsyun.baidu.com/apiconsole/key 下载SDK ● 下载百度地图开发包:http://api.map.baidu.com/lbsapi/clo ...
- ios添加百度地图方法
Hello BaiduMapiOS SDK 引入头文件 引入静态库文件 引入系统framework 引入mapapi.bundle资源文件 初始化BMKMapManager 创建BMKMapView ...
- Android集成百度地图详细步骤和错误问题
先看要实现的效果 第一步, 下载SDK,基础配置,百度开发文档很详细,直接附上链接http://lbsyun.baidu.com/index.php?title=androidsdk/guide/cr ...
- Android 开发之集成百度地图的定位与地图展示
app 应用中,大多数应用都具有定位功能,百度定位就成了开发人员的集成定位功能的首选,近期也在做定位功能,可是发现百度真是个大坑啊, sdk 命名更新了,相关代码却不更新,害得我花费了非常长时间来研究 ...
- iOS开发---集成百度地图
由于iOS MapKit框架很多情况并不能满足我们的需求,我们可以选择集成百度地图,那该如何操作呢? 申请Key 登录百度API管理中心申请Key http://lbsyun.baidu.com/ap ...
- iOS开发---集成百度地图,位置偏移问题
iOS 集成百度SDK 请参考 百度地图官方文档 ,这里不就多啰嗦了 本文介绍的是在百度地图上根据经纬度,自定义气泡时,气泡位置的偏移,在我们天朝这种事是很常见的,也见怪不怪了,在项目中使用的百度地图 ...
- iOS开发之集成百度地图踩过的那些坑(基于 Xcode7.0/iOS9.2)
本篇分4步讲述如何在项目中集成百度地图: 第一步:创建项目 第二步:利用 cocoaPod 导入百度地图的 SDK(pod 'BaiduMapKit' #百度地图SDK) 第三步:在 pch 文件中导 ...
- 微信公众号开发《三》微信JS-SDK之地理位置的获取,集成百度地图实现在线地图搜索
本次讲解微信开发第三篇:获取用户地址位置信息,是非常常用的功能,特别是服务行业公众号,尤为需要该功能,本次讲解的就是如何调用微信JS-SDK接口,获取用户位置信息,并结合百度地铁,实现在线地图搜索,与 ...
随机推荐
- [git 学习篇]删除文件
1 现在本地文件管理器删除了readme.txt(这个readme.txt已经在创库存在的) rm -rf readme.txt 2 此时git status查看 $ git status # On ...
- Wannafly挑战赛6
完全平方数 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K64bit IO Format: %lld 题目描述 多次查询[l,r]范围内的完全平方 ...
- [错误处理]python大小写敏感,关键字不要写错
今天调试程序,发现了一个极为隐蔽的bug. True False关键字大小写写错了,然后半天没找出问题所在.
- Set容器——HashSet及常用API
Set容器特点: ① Set容器是一个不包含重复元素的Collection,并且最多包含一个null元素,它和List容器相反,Set容器不能保证其元素的顺序; ② 最常用的两个Set接口的实 ...
- Spring 4.3.11.RELEASE文档阅读(二):Core Technologies_IOC
在看这部分内容的时候,想了一些问题: 容器: 1,什么是容器 用来包装或装载物品的贮存器 2,容器能做什么 包装或装载物品 3,为什么需要容器 为什么要使用集装箱?如果没有容器会是什么样? 4,常见的 ...
- you build it,you run it
this article is almostly about a book named Migrating_to_Microservices_Databases, and it's just the ...
- 设计模式(Java随笔)—装饰模式
装饰模式(Decorator Pattern):为已有功能动态地添加更多功能的一种方式Attach additional responsiblities to an object dynamicall ...
- CentOS7 Failed to start iptables.解决方法
Shit, CentOS怎么这么多bug.... 公司机房周日突然掉电,之前的Openstack环境就不能用了. 重新Run了一遍安装脚本,发现这个错误: iptables 咋又起不来了呢..... ...
- oracle 导出表结构信息
直接贴sql: select cols.table_name 表名, cols.column_name 列名, cols.data_type 字段类型, cols.data_length 长度, co ...
- 转 Python常见数据结构整理
http://www.cnblogs.com/jeffwongishandsome/archive/2012/08/05/2623660.html Python常见数据结构整理 Python中常见的数 ...