swift地图定位(二十)百度地图的使用(POI)
来源:互联网 发布:网络测试掉包工具 编辑:程序博客网 时间:2024/06/15 06:24
//// ViewController.swift// baidumapfirsttest//// Created by targetcloud on 2016/11/16.// Copyright © 2016年 targetcloud. All rights reserved.import UIKitclass ViewController: UIViewController { var _mapView: BMKMapView? lazy var searcher: BMKPoiSearch = { let searcher = BMKPoiSearch() searcher.delegate = self return searcher }() override func viewDidLoad() { super.viewDidLoad() _mapView = BMKMapView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)) self.view.addSubview(_mapView!) //设置起始中心点 let center = CLLocationCoordinate2D(latitude: 31.272881101147327, longitude: 121.61539365113157) _mapView?.centerCoordinate = center //设置区域 let span = BMKCoordinateSpanMake(0.011929035022411938, 0.0078062748817018246) let region = BMKCoordinateRegionMake(center, span) _mapView?.setRegion(region, animated: true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) _mapView?.viewWillAppear() searcher.delegate = self _mapView?.delegate = self // 此处记得不用的时候需要置nil,否则影响内存的释放 } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) _mapView?.viewWillDisappear() searcher.delegate = nil _mapView?.delegate = nil // 不用时,置nil }}extension ViewController: BMKMapViewDelegate { func mapview(_ mapView: BMKMapView!, onLongClick coordinate: CLLocationCoordinate2D) { print(coordinate);//CLLocationCoordinate2D(latitude: 31.273070191233703, longitude: 121.61624006488663) // 调整区域 根据长按的位置 let span = BMKCoordinateSpanMake(0.011929035022411938, 0.0078062748817018246) let region = BMKCoordinateRegionMake(coordinate, span) mapView.setRegion(region, animated: true) let option = BMKNearbySearchOption() option.pageIndex = 0 option.pageCapacity = 20 option.location = coordinate//根据长按的位置 option.keyword = "小吃" let flag = searcher.poiSearchNear(by: option) if flag{ print("周边检索发送成功") }else{ print("周边检索发送失败") } } //点击大头针 func mapView(_ mapView: BMKMapView!, annotationViewForBubble view: BMKAnnotationView!) { let annotaiton = view.annotation print(">>>\(annotaiton?.coordinate)\(annotaiton?.title!())\(annotaiton?.subtitle!())")//>>>Optional(__C.CLLocationCoordinate2D(latitude: 31.273627860569221, longitude: 121.61636597701556))Optional("美滋滋零食")Optional("上海市浦东新区") } //区域改变 func mapView(_ mapView: BMKMapView!, regionDidChangeAnimated animated: Bool) { print(mapView.region.center,mapView.region.span)//CLLocationCoordinate2D(latitude: 31.272873385065104, longitude: 121.61537568502136) BMKCoordinateSpan(latitudeDelta: 0.011921347023825746, longitudeDelta: 0.0078062748817018246) }}extension ViewController: BMKPoiSearchDelegate { func onGetPoiResult(_ searcher: BMKPoiSearch!, result poiResult: BMKPoiResult!, errorCode: BMKSearchErrorCode) { if errorCode == BMK_SEARCH_NO_ERROR { print("周边检索成功") print(poiResult.poiInfoList) let poiInfos = poiResult.poiInfoList as! [BMKPoiInfo] for poiInfo in poiInfos { print(poiInfo.name, poiInfo.address) //加大头针 let annotation = BMKPointAnnotation() annotation.coordinate = poiInfo.pt//CLLocationCoordinate2D annotation.title = poiInfo.name annotation.subtitle = poiInfo.address _mapView?.addAnnotation(annotation) } }else { print("周边检索失败") } }}/* 周边检索发送成功 周边检索成功 [<BMKPoiInfo: 0x6000002b0e60>, <BMKPoiInfo: 0x6000002af3c0>, <BMKPoiInfo: 0x6000002b0200>, <BMKPoiInfo: 0x6000002b0e00>, <BMKPoiInfo: 0x6000002b1ee0>, <BMKPoiInfo: 0x6000002af300>, <BMKPoiInfo: 0x6000002a6d20>, <BMKPoiInfo: 0x6000002af060>, <BMKPoiInfo: 0x6000002b01a0>, <BMKPoiInfo: 0x6000002b1f40>, <BMKPoiInfo: 0x6000002b0da0>, <BMKPoiInfo: 0x6000002b3920>, <BMKPoiInfo: 0x6000002b0f20>, <BMKPoiInfo: 0x6000002a6e40>, <BMKPoiInfo: 0x6000002b3260>, <BMKPoiInfo: 0x6000002bd400>, <BMKPoiInfo: 0x6000002b3500>, <BMKPoiInfo: 0x6000002b3320>, <BMKPoiInfo: 0x6000002b3380>, <BMKPoiInfo: 0x6000002b3980>] 绝味鸭脖(佳林路二店) 佳林路161号底层 2016-11-16 17:11:35.399825 baidumapfirsttest[6234:238428] [Graphics] UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once. 林家面馆 佳林路147号(近金高路) 上海面馆 金高路2072号(东陆路口) 和府私房牛肉面 佳林路88号 渝客麻辣烫(金高路店) 金高路1736号(廊亦舫对面) 东北味小吃 佳林路125号 百年龙袍蟹黄汤包(金桥店) 金高路1757号金桥佳邻坊1F 巴比馒头(东陆路) 浦东新区东陆公路与金高路交叉口旁 李记红烧牛肉面麻辣烫 金高路2066号 正宗潮汕砂锅粥 金高路1897号 金桥汇 金高路1777号金桥文体中心4楼 来伊份(NO.3521店) 东陆公路1980号 沙县小吃 金高路1788号 精品黄焖鸡米饭 金高路2068号(东陆路) 蒸味坊馒头 上海市浦东新区金高路1764号 重庆鸡公煲巫山烤全鱼 佳林路137号 银记桂林米粉 上海市浦东新区 塞北风 金高路2088号 美滋滋零食 上海市浦东新区 沙县小吃 上海市浦东新区 */
0 0
- swift地图定位(二十)百度地图的使用(POI)
- swift地图定位(十九)集成百度地图
- 百度地图开发(二)POI检索
- 百度地图的定位和poi搜索
- 百度地图使用教程(二)-------- 定位实现
- swift地图定位(十六)poi及其他
- android百度地图(二)之定位
- 百度地图 baiduMap(二) 定位
- Android百度地图开发(二)-定位
- Android之百度地图(二)基础地图和定位
- swift地图定位(十五)使用MKUserTrackingBarButtonItem
- 百度地图定位的使用
- 百度地图的使用(定位)
- 百度地图定位的使用
- swift地图定位(九)github-LocationManager的使用
- swift地图定位(十二)大头针的基本使用
- 百度地图sdk使用(2) 定位
- Android 百度地图开发(二)--- 定位功能之MyLocationOverlay,PopupOverlay的使用
- Altisum designer制板实用功能及对应快捷键小结:
- [问题解决] maven仓库下载缓慢
- Shiro的异常处理
- 仿微信图库文件夹选择的交互
- 机器学习--AdaBoost算法
- swift地图定位(二十)百度地图的使用(POI)
- 签名方法
- 一款车载GPS定位产品后端服务器架构的填坑之路(一)
- 错误代码 ILLEGAL_PARTNER_EXTERFACE 解决
- 螺旋数组的输出
- 通过JDBC连接oracle数据库的十大技巧
- Android右划喜欢左划不喜欢的View
- ACM专栏(长期更新)
- iOS - JLRoutes路由跳转