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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS百度地图的使用

發布時間:2025/4/5 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS百度地图的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

????項目最近對地圖整體模塊進行了重構, 為了和我們的安卓同學保持統一,放棄了原本就很6的高德地圖,全部改用百度地圖(雖然我覺得百度地圖不好用,文檔也一般,但是沒辦法啊,沒辦法啊 啊啊啊啊啊..).

項目中用到的百度地圖的主要功能點有以下幾個:

  • 基礎地圖和定位
  • 反地理編碼功能
  • poi檢索
  • 搜索建議和poi詳情檢索
  • 區域檢索功能
  • 通過url調起第三方地圖進行
  • 自定義彈出泡泡
  • ?在實際的使用過程中這些功能可能會有交叉,所以代碼會整個貼過來,下面就根據實際功能需求一一介紹.

    一.基礎地圖和定位功能

    地圖的初始化:

    - (void)initMapView {self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_WIDTH/372*253)];self.mapView.showsUserLocation = YES;self.mapView.userTrackingMode = BMKUserTrackingModeNone;self.mapView.gesturesEnabled = YES;self.mapView.zoomEnabled = YES;self.mapView.maxZoomLevel = 23;self.mapView.zoomLevel = 16;// 顯示比例尺 200m (和微信一樣....)self.mapView.showMapScaleBar = YES;// 回到當前位置按鈕UIButton *showUserLocation = [[UIButton alloc] initWithFrame:CGRectMake(self.mapView.mj_width - 21 - 50, self.mapView.mj_height - 21 - 50, 50, 50)];[self.mapView addSubview:showUserLocation];[showUserLocation addTarget:self action:@selector(backToCurrentLocation) forControlEvents:UIControlEventTouchUpInside];[showUserLocation setBackgroundImage:[UIImage imageNamed:@"showuserlocation"] forState:UIControlStateNormal];UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.mapView.mj_width * 0.5 - 8, self.mapView.mj_height * 0.5 - 40, 16, 40)];imageView.image = [UIImage imageNamed:@"datouzhen"];imageView.contentMode = UIViewContentModeScaleAspectFit;[self.mapView addSubview:imageView];[self.view addSubview:self.mapView]; }

    這里提醒一點百度地圖各項服務的delegate需要在 viewWillApper設置為self,viewWillDisapper時設置為nil,否則的話會出現內存泄露.

    以下是定位成功后的回調方法

    /***用戶位置更新后,會調用此函數*@param userLocation 新的用戶位置*/ - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation {[self.mapView updateLocationData:userLocation];CLLocation *location = userLocation.location;// 如果不是區域檢索if (!(self.city.length > 0)) {// 設置當前位置為地圖的中心點NSLog(@"%f-----%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude) animated:YES];}self.currentCoor = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);// 定位成功會后if (location) {[self.locationService stopUserLocationService];// 反向編碼[self beginReverseGeoCodeSearch];} }

    這里進行了判斷,如果不是區域檢索(如果我人在北京,但是要讓地圖顯示是石家莊市 此時需要用到區域檢索),則將當前定位到的位置設置為地圖的中心點 . 然后開始進行反地理編碼.

    二.反地理編碼

    因為在發布分享的時候有一個選項顯示的是當前所在的城市,如下圖一,二 ?. 第二個cell顯示的 "北京市"?所以需要進行反地理編碼.

    反地理編碼成功后的回調:

    // 反地理編碼回調 - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error {// result ->poiList ///地址周邊POI信息,成員類型為BMKPoiInfo // @property (nonatomic, strong) NSArray* poiList;if (result.poiList.count > 0) {self.currentPoiInfo = [result.poiList firstObject];}// 反向地理編碼成功后 ,進行poi搜索[self beginPoiSearch:self.currentCoor keyword:@""]; }

    三.poi 檢索

    百度地圖poi只能設置一個關鍵字(也有可能是我沒找到方法,如果可以設置多個請及時聯系,謝謝)?

    發起poi檢索?

    #pragma mark ----發起檢索 // 發起poi檢索 - (void)beginPoiSearch:(CLLocationCoordinate2D)coor keyword:(NSString *)keyowrd{BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];option.pageCapacity = 50;// 按距離排序option.sortType = BMK_POI_SORT_BY_DISTANCE;// 以地圖中心點為坐標發起檢索 默認keyword 寫字樓option.location = CLLocationCoordinate2DMake(coor.latitude, coor.longitude);option.keyword = keyowrd.length > 0 ? keyowrd : @"寫字樓";BOOL flag = [self.poiSearch poiSearchNearBy:option];NSLog(@"%@",flag ? @"周邊檢索發送成功" : @"周邊檢索發送失敗"); }

    poi檢索發起成功后的頁面展示如下圖:

    ?? ? ? ?

    ? 圖 一????????????????????????????????????????????????????????????????? ? ?圖 二

    這里除了poi檢索之外,還加了一個地圖中心點功能,及拖動地圖的時候以大頭針的位置為當前地圖的中心點,然后再進行poi檢索.這里需要監聽另外一個回調方法.

    // 拖拽地圖的回調 - (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {[self beginPoiSearch:self.mapView.centerCoordinate keyword:self.keyword.length > 0 ? self.keyword : @""]; }

    在這個回調方法中,以當前地圖的中心為poi檢索的中心點 發起poi檢索.

    四.搜索建議功能和poi詳情檢索

    搜搜建議功能截圖如下圖:

    在serchDisplayController的代理方法中發送搜索建議的請求:

    #pragma mark ---displayControllerDelegate - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {self.searchText = searchString;self.suggestSearch = [[BMKSuggestionSearch alloc]init];self.suggestSearch.delegate = self;BMKSuggestionSearchOption* option = [[BMKSuggestionSearchOption alloc] init];option.cityname = self.city;option.keyword = searchString;BOOL flag = [self.suggestSearch suggestionSearch:option];NSLog(@"%@",flag ? @"建議檢索發送成功" : @"建議檢索發送失敗");return YES; }

    然后在其回調方法中處理搜索建議結果:

    // 搜索建議返回的關鍵詞list和區list ,coor list,poi id list @property (nonatomic,strong)NSMutableArray *keyList; // 萬達廣場 @property (nonatomic,strong)NSMutableArray *districtList; // 海淀區 @property (nonatomic,strong)NSMutableArray *coorList; // coor 包裝成的 NSValue對象 @property (nonatomic,strong)NSMutableArray *poiuIdList; // poi id- (void)onGetSuggestionResult:(BMKSuggestionSearch *)searcherresult:(BMKSuggestionResult *)resulterrorCode:(BMKSearchErrorCode)error {self.keyList = [NSMutableArray arrayWithCapacity:0];self.districtList = [NSMutableArray arrayWithCapacity:0];self.coorList = [NSMutableArray arrayWithCapacity:0];self.poiuIdList = [NSMutableArray arrayWithCapacity:0];NSMutableArray *emptyLocationArray = [NSMutableArray arrayWithCapacity:0];for (int i = 0; i<result.ptList.count; i++) {CLLocationCoordinate2D coor;NSValue *coorValue = result.ptList[i];[coorValue getValue:&coor];// 非空的地址加到數組中if (!((int)coor.latitude == 0 && (int)coor.longitude == 0)) {[emptyLocationArray addObject:[NSString stringWithFormat:@"%d",i]];[self.keyList addObject:result.keyList[i]];[self.districtList addObject:result.districtList[i]];[self.coorList addObject:result.ptList[i]];[self.poiuIdList addObject:result.poiIdList[i]];}}[self.displayController.searchResultsTableView reloadData]; }

    點擊搜索建議tableView的cell時,需要mapView跳轉到對應的位置,并搜索其附近對應的poi信息(比如我點的結果是個餐廳,那么就地圖就滾動到這個餐廳的位置,并以"餐飲"為關鍵詞搜索附近的poi信息),所以這里需要用到另外一個接口:poi詳情搜索(注意是poi詳情搜索,兩個有點像)

    點擊cell時,根據poi 的id發起poi詳情搜索?:

    // 發起poi 詳情檢索 - (void)beginPoiDetailSearch:(NSString *)uid {BMKPoiDetailSearchOption* option = [[BMKPoiDetailSearchOption alloc] init];option.poiUid = uid;//POI搜索結果中獲取的uidBOOL flag = [self.poiSearch poiDetailSearch:option];NSLog(@"%@",flag ? @"POI詳情檢索發送成功" : @"POI詳情檢索發送失敗"); }

    poi詳情檢索成功后的回調:

    - (void)onGetPoiDetailResult:(BMKPoiSearch *)searcher result:(BMKPoiDetailResult *)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode {CLLocationCoordinate2D coor;NSValue *coorValue = self.coorList[self.searchResultSelectedIndexPath.row];[coorValue getValue:&coor];self.keyword = poiDetailResult.tag;// 改變中心坐標[self.mapView setCenterCoordinate:coor animated:YES];[self beginPoiSearch:coor keyword:poiDetailResult.tag]; }

    返回的結果是?BMKPoiDetailResult 對象,里面包含了 poi的詳細信息,包括 name address tag(poi標簽)等.

    然后以?poiDetailResult.tag 為關鍵字進行poi搜索.

    五.區域檢索功能

    我人在北京,但是想查看石家莊的景點,小吃等信息 . ?此時就需要用到區域檢索功能了. 先判斷

    if (self.city.length > 0) {

    ? ? ? ? [self beginDistrictSearch];

    ? ? }?如果傳過來的城市的名字長度大于 0 則說明要先進行區域檢索.

    // 發起區域檢索 - (void)beginDistrictSearch {//初始化檢索對象self.districtSearch = [[BMKDistrictSearch alloc] init];//設置delegate,用于接收檢索結果self.districtSearch.delegate = self;//構造行政區域檢索信息類BMKDistrictSearchOption *option = [[BMKDistrictSearchOption alloc] init];option.city = self.city;option.district = self.district;//發起檢索BOOL flag = [self.districtSearch districtSearch:option];NSLog(@"%@",flag ? @"區域檢索發送成功" : @"區域檢索發送失敗"); }

    區域檢索成功后的回調:

    - (void)onGetDistrictResult:(BMKDistrictSearch *)searcher result:(BMKDistrictResult *)result errorCode:(BMKSearchErrorCode)error {NSLog(@"---->%f----%f",result.center.latitude,result.center.longitude);// 設置地圖中心點[self.mapView setCenterCoordinate:result.center animated:YES];// 以城市中心點為中心發起poi檢索[self beginPoiSearch:result.center keyword:@""]; }

    這樣就可以實現檢索不同省份城市的 poi信息了.

    六.通過url調起第三方地圖進行

    效果如下圖:

    ?? ? ?

    點擊上面導航按鈕會進行判斷,判斷當前app是否安裝了高德,百度以及蘋果自帶的地圖 如果有則將其展示出來否則則不顯示. 點擊之后則會調起對應的地圖進行導航,具體實現可以看我這篇博客 iOS通過URL調起第三方地圖進行導航

    七.自定義彈出pop

    效果如下圖:

    點擊大頭針彈出pop ,這里的pop是自己繪制的代碼:

    @interface BubbleView : UIView@end@implementation BubbleView- (void)drawRect:(CGRect)rect {[super drawRect:rect];CGFloat width = rect.size.width;CGFloat height = rect.size.height;CGFloat radius = 5;CGFloat jianjiaoH = 12;// 獲取CGContext,注意UIKit里用的是一個專門的函數CGContextRef context = UIGraphicsGetCurrentContext();// 移動到初始點CGContextMoveToPoint(context, radius, 0);// 繪制第1條線和第1個1/4圓弧CGContextAddLineToPoint(context, width - radius, 0);CGContextAddArc(context, width - radius, radius, radius, -0.5 * M_PI, 0.0, 0);// CGContextAddArc(<#CGContextRef _Nullable c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)// 繪制第2條線和第2個1/4圓弧 17CGContextAddLineToPoint(context, width, height - radius - jianjiaoH);CGContextAddArc(context, width - radius, height - radius - jianjiaoH, radius, 0.0, 0.5 * M_PI, 0);// 繪制第3條線和第3個1/4圓弧和尖角CGContextAddLineToPoint(context, width/2 + 9, height - jianjiaoH);CGContextAddLineToPoint(context, width/2, height);CGContextAddLineToPoint(context, width/2 - 9, height - jianjiaoH);CGContextAddLineToPoint(context, width - radius, height - jianjiaoH);CGContextAddArc(context, radius, height - radius - jianjiaoH, radius, 0.5 * M_PI, M_PI, 0);// 繪制第4條線和第4個1/4圓弧CGContextAddLineToPoint(context, 0, radius);CGContextAddArc(context, radius, radius, radius, M_PI, 1.5 * M_PI, 0);// 閉合路徑CGContextClosePath(context);// 填充半透明黑色CGContextSetRGBFillColor(context, 0, 0, 0.0, 0.5);CGContextDrawPath(context, kCGPathFill); }@end

    至此,此次我們用的百度地圖的功能已經全部分享給大家了,如果紕漏請指正 .全部的代碼我貼在動彈里了 -_-

    轉載于:https://my.oschina.net/zhxx/blog/748468

    總結

    以上是生活随笔為你收集整理的iOS百度地图的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 在线免费观看欧美大片 | 国产精品成人免费一区二区视频 | aaa黄色片 | 制服一区二区 | aaa黄色一级片 | 欧美啪啪小视频 | 超碰91在线 | 99re这里只有精品在线观看 | 理论片一级 | 久久久久久人妻一区二区三区 | 91一区二区在线观看 | 中文字幕一区二区三区免费看 | 68日本xxxxxⅹxxx22| 国产crm系统91在线 | 91精品国产综合久久精品图片 | 丰满少妇一区二区 | 中文字幕一区2区3区 | 日本福利一区二区三区 | 欧美亚洲图片小说 | 综合xx网 | 成人免费观看视频大全 | 国产精品久久久久久人 | 日韩一区二区精品视频 | 日本xxx在线播放 | 人妻少妇精品无码专区久久 | 午夜高清视频 | 国产精品视频久久久 | 欧美日韩一区二区三区四区 | 乳揉みま痴汉4在线播放 | jizzjizz国产 | 亚洲色图36p | 天天天天色 | 久久久精品国产免费爽爽爽 | 爱爱视频网址 | 欧美狂猛xxxxx乱大交3 | 青青成人网 | 欧美九九 | 99碰碰 | h片免费观看 | 亚洲图片综合网 | 国产五月 | 好邻居韩国剧在线观看 | 国产精品视频区 | 亚洲精品一区二三区不卡 | 国产精品一区无码 | 亚洲成年| 成人高清在线 | 亚洲无码一区二区三区 | 亚洲精品嫩草 | 好男人网站 | 午夜伦理在线观看 | 蜜桃视频污在线观看 | 麻豆影视网站 | 在线视频久久 | 美女喷液视频 | 无码国产色欲xxxx视频 | 在线观看高h | 午夜999| 精品一区二区三区人妻 | 午夜寂寞影院在线观看 | 日批在线播放 | 亚欧成人在线 | 91免费高清| 日日色综合| 伊人网在线免费观看 | 超碰免费在线观看 | jizz欧美性11 | 日p免费视频 | 男女男精品视频 | 中文字幕精品一区二区精 | 国产成人无码久久久精品天美传媒 | 欲求不满在线小早川怜子 | 国内精品亚洲 | 人妻少妇被猛烈进入中文字幕 | 日韩天堂视频 | 欧美日本韩国一区二区 | 中文字幕一区日韩 | 中文字幕人妻无码系列第三区 | 宅男噜噜噜666在线观看 | 国产又好看的毛片 | 欧美午夜精品一区 | 天堂在线国产 | 射区导航 | 91黄色小网站 | 性激情视频 | 国产精品亚洲视频 | 久色影视 | 可以在线观看av的网站 | 99亚洲国产精品 | 成年人视频在线看 | 欧美在线日韩在线 | 99爱在线观看 | 黄色国产小视频 | 日本免费一二三区 | 九一成人网 | 亚洲国产精品成人综合色在线婷婷 | 国产精品综合网 | av天堂一区二区 | 中文字幕――色哟哟 |