日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

百度地图之室内地图

發(fā)布時(shí)間:2024/3/24 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 百度地图之室内地图 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

召喚代碼君:

頭文件

#import "RoomViewController.h"

#import <BaiduMapAPI_Map/BMKMapView.h>

#import <BaiduMapAPI_Location/BMKLocationService.h>

#import <BaiduMapAPI_Search/BMKPoiSearch.h>

#import <BaiduMapAPI_Search/BMKRouteSearch.h>

#import "RoutAnnotation.h"

#import "LocationTransform.h"

//note:RoutAnnotation.h是直接用的百度提供的demo中的,在這個(gè)文件中用到了UIImage+Rotate.h,也是用的百度demo中的,百度demo下載地址:http://lbsyun.baidu.com/index.php?title=iossdk/sdkiosdev-download

添加屬性:

@interface RoomViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate, BMKPoiSearchDelegate,BMKRouteSearchDelegate>


@property (nonatomic,strong) BMKMapView *mapView; ? ? ? ? ?//地圖視圖

@property (nonatomic,strong) BMKLocationService *service; ?//定位

@property (nonatomic,strong) BMKPoiSearch *poiSearch; ? ? ?//poi搜索

@property (nonatomic,strong) BMKRouteSearch *routeSearch; ?//路線搜索

@property (nonatomic,strong) BMKBaseIndoorMapInfo *indoorMaInfo;//存儲(chǔ)當(dāng)前聚焦的室內(nèi)圖


@property (nonatomic,strong) CLLocation *myLocation;



@end


- (void)viewDidLoad {

? ? [superviewDidLoad];

? ? // Do any additional setup after loading the view.

?? ?

? ? [selfgetCoordinateByAddress:@"浙江省杭州市西湖區(qū)三墩鎮(zhèn)古墩路SCPG印象城購(gòu)物中心"];

?? ?

}

#pragma mark - 根據(jù)地名確定地理坐標(biāo)


-(void)getCoordinateByAddress:(NSString *)address {

? ? //地理編碼

? ? CLGeocoder *geocode = [[CLGeocoderalloc] init];

? ? [geocode geocodeAddressString:addresscompletionHandler:^(NSArray<CLPlacemark *> *_Nullable placemarks, NSError *_Nullable error) {

? ? ? ? CLPlacemark *placemark = [placemarksfirstObject];

?? ? ? ?

? ? ? ? CLLocation *location = placemark.location;//位置

? ? ? ? NSLog(@"位置經(jīng)緯度:%f, %f", location.coordinate.latitude, location.coordinate.longitude);

?? ? ? ?

?? ? ? ?

? ? ? ? //地球坐標(biāo)轉(zhuǎn)百度坐標(biāo),因?yàn)榈乩砭幋a得到的是地球坐標(biāo)(WGS-84,所以要在這里轉(zhuǎn)成百度坐標(biāo)(BD-09

? ? ? ? LocationTransform *locationTranform = [[LocationTransformalloc] initWithLatitude:location.coordinate.latitudeandLongitude:location.coordinate.longitude];

? ? ? ? locationTranform = [locationTranform transformFromGDToBD];

?? ? ? ?

? ? ? ? CLLocationCoordinate2D afterCoor =CLLocationCoordinate2DMake(locationTranform.latitude, locationTranform.longitude);

?? ? ? ?

? ? ? ? //初始化地圖

? ? ? ? self.mapView = [[BMKMapViewalloc] initWithFrame:self.view.bounds];

? ? ? ? self.mapView.centerCoordinate = afterCoor;

? ? ? ? self.mapView.baseIndoorMapEnabled =YES; ? //打開(kāi)室內(nèi)地圖

? ? ? ? self.mapView.zoomLevel =19;

?? ? ? ?

? ? ? ? self.poiSearch = [[BMKPoiSearchalloc] init];

? ? ? ? self.routeSearch = [[BMKRouteSearchalloc] init];

?? ? ? ?

? ? ? ? self.mapView.delegate =self;

? ? ? ? self.poiSearch.delegate =self;

? ? ? ? self.routeSearch.delegate =self;

?? ? ? ?

? ? ? ? /*

? ? ? ? //添加室內(nèi)路線檢索入口

? ? ? ? UIBarButtonItem *customRightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"室內(nèi)路線" style:UIBarButtonItemStyleBordered target:self action:@selector(indoorRoutePlanSearch)];

? ? ? ? self.navigationItem.rightBarButtonItem = customRightBarButtonItem;

? ? ? ? */

?? ? ? ?

? ? ? ? self.indoorMaInfo = [[BMKBaseIndoorMapInfoalloc] init];

?? ? ? ?

? ? ? ? [self.viewaddSubview:self.mapView];


?? ? ? ?

? ? ? ? UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

? ? ? ? button.frame =CGRectMake(10,200, 80,35);

? ? ? ? button.backgroundColor = [UIColorlightGrayColor];

? ? ? ? button.layer.cornerRadius =5;

? ? ? ? button.layer.masksToBounds =YES;

? ? ? ? [button setTitle:@"室內(nèi)檢索"forState:UIControlStateNormal];

? ? ? ? [button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

? ? ? ? [button addTarget:selfaction:@selector(handleAction:)forControlEvents:UIControlEventTouchUpInside];

? ? ? ? [self.viewaddSubview:button];


?? ? ? ?

? ? }];

}



#pragma mark - BMKMapView Delegate


//監(jiān)聽(tīng)進(jìn)入和移出室內(nèi)圖時(shí)間

-(void)mapview:(BMKMapView *)mapView baseIndoorMapWithIn:(BOOL)flag baseIndoorMapInfo:(BMKBaseIndoorMapInfo *)info {

?? ?

? ? NSLog(@"flag == %d", flag);

?? ?

? ? if (flag) {

? ? ? ? //進(jìn)入室內(nèi)圖

?? ? ? ?

? ? ? ? NSLog(@"進(jìn)入室內(nèi)圖");

?? ? ? ?

? ? ? ? if (info !=nil && info.arrStrFloors.count >0) {

? ? ? ? ? ? self.indoorMaInfo.strID = info.strID;

? ? ? ? ? ? self.indoorMaInfo.strFloor = info.strFloor;

? ? ? ? ? ? self.indoorMaInfo.arrStrFloors = info.arrStrFloors;

? ? ? ? }

? ? }else {

? ? ? ? //移出室內(nèi)圖

? ? ? ? NSLog(@"移出室內(nèi)圖");

? ? }

?? ?

}



-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {

?? ?

? ? NSLog(@"大頭針的設(shè)置方法");

?? ?

? ? if ([annotationisKindOfClass:[RoutAnnotationclass]]) {

? ? ? ? return [(RoutAnnotation *)annotationgetRouteAnnotationView:mapView];

? ? }

? ? returnnil;

}


#pragma mark - handle action


//發(fā)起室內(nèi)檢索

-(void)handleAction:(UIButton *)button {

?? ?

? ? NSArray *annotationArr = [NSArrayarrayWithArray:self.mapView.annotations];

? ? [self.mapViewremoveAnnotations:annotationArr];

?? ?

? ? NSArray *overlayAr = [NSArrayarrayWithArray:self.mapView.overlays];

? ? [self.mapViewremoveOverlays:overlayAr];

?? ?

? ? BMKPoiIndoorSearchOption *option = [[BMKPoiIndoorSearchOptionalloc] init];

? ? option.indoorId =self.indoorMaInfo.strID;

? ? option.keyword =@"餐廳";

? ? option.pageIndex =0;

? ? option.pageCapacity =20;

?? ?

? ? BOOL flag = [self.poiSearchpoiIndoorSearch:option];

? ? if (!flag) {

? ? ? ? NSLog(@"室內(nèi)檢索發(fā)送失敗");

? ? }else {

? ? ? ? NSLog(@"室內(nèi)檢索發(fā)送成功");

? ? }

}

#pragma mark - BMKPoiSearch Delegate



/**

?*?返回POI室內(nèi)搜索結(jié)果

?*

?*? @param searcher? ? ? ? 搜索對(duì)象

?*? @param poiIndoorResult 搜索結(jié)果列表

?*? @param errorCode ? ? ? 錯(cuò)誤號(hào),@see BMKSearchErrorCode

?*/

-(void)onGetPoiIndoorResult:(BMKPoiSearch *)searcher result:(BMKPoiIndoorResult *)poiIndoorResult errorCode:(BMKSearchErrorCode)errorCode {

?? ?

? ? NSLog(@"返回POI室內(nèi)搜索結(jié)果方法");

?? ?

? ? NSArray *array = [NSArrayarrayWithArray:self.mapView.annotations];

? ? [self.mapViewremoveAnnotations:array];

?? ?

? ? if (errorCode ==BMK_SEARCH_NO_ERROR) {

? ? ? ? //成功獲取結(jié)果

? ? ? ? for (BMKPoiIndoorInfo *infoin poiIndoorResult.poiIndoorInfoList) {

? ? ? ? ? ? NSLog(@"name:%@ uid:%@", info.name, info.uid);

?? ? ? ? ? ?

? ? ? ? ? ? BMKPointAnnotation *annotation = [[BMKPointAnnotationalloc] init];

? ? ? ? ? ? annotation.title = info.name;

? ? ? ? ? ? annotation.coordinate = info.pt;

? ? ? ? ? ? [self.mapViewaddAnnotation:annotation];

? ? ? ? }

?? ? ? ?

? ? }else {

? ? ? ? //檢索失敗

? ? ? ? NSLog(@"檢索失敗,沒(méi)有獲取到結(jié)果");

? ? }

}

//注釋:LocationTransform是在網(wǎng)上找到的坐標(biāo)轉(zhuǎn)化方法,地址:http://www.jianshu.com/p/abdb35b0ba78

/**

?*? 遇到的問(wèn)題:

?*? 1.handleAction方法中打印 室內(nèi)檢索發(fā)送失敗 時(shí),檢查一下option.indoorId是否存在

? ? 2.如果不走mapview: baseIndoorMapWithIn: baseIndoorMapInfo:方法,檢查一下是否設(shè)置了代理

? ? 3.如果定位有偏差,檢查根據(jù)地名獲取坐標(biāo)時(shí)是否轉(zhuǎn)換成了百度坐標(biāo)

?*/



總結(jié)

以上是生活随笔為你收集整理的百度地图之室内地图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。