全景上车点
功能场景
乘客选择推荐上车点时,可以通过查看全景图进一步确认上车点周围的环境,帮助用户快速选择正确的上车点。
iOS

//mapopen-website-wiki.bj.bcebos.com/demos/spananPic/panana1.mp4

扫码体验
核心接口
类
接口
描述
BMKSuggestionSearch
- (void)onGetSuggestionResult:(BMKSuggestionSearch *)searcher result:(BMKSuggestionSearchResult *)result errorCode:(BMKSearchErrorCode)error
返回关键字检索结果
BMKGeoCodeSearch
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error
根据关键字检索选中的位置进行逆地理编码
BMKRecommendStopSearch
- (void)onGetRecommendStopResult:(BMKRecommendStopSearch *)searcher result:(BMKRecommendStopSearchResult *)recommendStopResult errorCode:(BMKSearchErrorCode)errorCode
进行推荐上车点请求,得到推荐上车点数据
全景静态图WebAPI
请求全景静态图
- (void)panoramaDidLoad:(BaiduPanoramaView *)panoramaView descreption:(NSString *)jsonStr
创建全景图完毕
BaiduPanoramaView
- (void)panoramaView:(BaiduPanoramaView *)panoramaView didReceivedMessage:(NSDictionary *)dict
旋转全景图
核心代码
1、关键字匹配查询
BMKSuggestionSearchOption *option = [BMKSuggestionSearchOption new]; option.keyword = key; option.cityname = @"北京市"; option.cityLimit = YES; BMKSuggestionSearch *sugSearch = [BMKSuggestionSearch new]; sugSearch.delegate = self; [sugSearch suggestionSearch:option];
2、逆地理编码检索
BMKGeoCodeSearch *search = [[BMKGeoCodeSearch alloc] init]; search.delegate = self; BMKReverseGeoCodeSearchOption *reverseGeoCodeOption = [[BMKReverseGeoCodeSearchOption alloc]init]; reverseGeoCodeOption.location = coordinate; reverseGeoCodeOption.isLatestAdmin = YES; BOOL flag = [search reverseGeoCode: reverseGeoCodeOption]; if (flag) { NSLog(@"逆geo检索发送成功"); } else { NSLog(@"逆geo检索发送失败"); }
3、请求推荐上车点数据
// 初始化请求参数类BMKRecommendStopSearchOption的实例 BMKRecommendStopSearchOption *option = [[BMKRecommendStopSearchOption alloc] init]; // 推荐上车点经纬度 (必选) option.location = coordinate; // 初始化BMKRecommendStopSearch实例 BMKRecommendStopSearch *search = [[BMKRecommendStopSearch alloc] init]; // 推荐上车点检索的代理 search.delegate = self; // 初始化请求参数类BMKRecommendStopSearchOption的实例 BMKRecommendStopSearchOption *stopSearchOption = [[BMKRecommendStopSearchOption alloc] init]; // 推荐上车点经纬度 (必选) stopSearchOption.location = option.location; /// 推荐上车点检索 BOOL flag = [search recommendStopSearch:stopSearchOption]; if (flag) { NSLog(@"推荐上车点检索成功"); } else { NSLog(@"推荐上车点检索失败"); }
4、请求全景静态图
NSString *urlString = [NSString stringWithFormat:@"https://api.map.baidu.com/panorama/v2?ak=您的ak&location=%f,%f&fov=180", info.location.longitude, info.location.latitude]; NSURL *listURL = [NSURL URLWithString:urlString]; NSURLSession * session= [NSURLSession sharedSession]; NSURLSessionDataTask * dataTask= [session dataTaskWithURL:listURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { if (!error) { dispatch_async(dispatch_get_main_queue(), ^{ if ([UIImage imageWithData:data]) { self.customPopView.panoImage = [UIImage imageWithData:data]; } }); } }]; [dataTask resume];
5、创建全景静态图
// key 为在百度LBS平台上统一申请的接入密钥ak 字符串 self.panoramaView = [[BaiduPanoramaView alloc] initWithFrame:frame key:@"您的ak"]; [self.panoramaView setAgreePrivacy:YES]; // 为全景设定一个代理 self.panoramaView.delegate = self; [self.view addSubview:self.panoramaView]; // 设定全景的清晰度, 默认为middle [self.panoramaView setPanoramaImageLevel:ImageDefinitionMiddle]; // 根据坐标转成全景使用的百度墨卡托坐标系 CGPoint point = BMKConvertToBaiduMercatorFromBD09LL(_coordinate); // 设定全景的pid, 这是指定显示某地的全景,也可以通过百度坐标进行显示全景 [self.panoramaView setPanoramaWithX:point.x Y:point.y];
6、创建全景静态图
// 百度墨卡托坐标 CGPoint point = BMKConvertToBaiduMercatorFromBD09LL(_coordinate); // 添加全景overlay [panoramaView addImageOverlayById:@"1" X:point.x Y:point.y Z:0 image:[UIImage imageNamed:@"stop_new"]];
7、获取全景图方向
float heading = panoramaView.getPanoramaHeading; float mapAngle = self.mapView.getMapStatus.fRotation; if (mapAngle > 0) { heading = ((heading - mapAngle) / 180.0 * M_PI); } else { heading = (heading / 180.0 * M_PI); } // 根据全景图的旋转方向设置地图上对应annotationView的方向 [UIView animateWithDuration:0.1 animations:^{ // 根据全景图旋转角度设置annotationView的角度, BMKAnnotationView *annotationView = [self.mapView viewForAnnotation:self.pointAnnotation]; annotationView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, heading); }];