swift地图定位(十六)poi及其他
来源:互联网 发布:淘宝客自动转换工具 编辑:程序博客网 时间:2024/05/29 07:08
import UIKitimport MapKitclass ViewController: UIViewController { @IBOutlet weak var mapView: MKMapView! lazy var locationM: CLLocationManager = { let locationM = CLLocationManager() if #available(iOS 8.0, *) { locationM.requestAlwaysAuthorization() } return locationM }() override func viewDidLoad() { super.viewDidLoad() mapView.delegate = self mapView.userTrackingMode = MKUserTrackingMode.followWithHeading _ = locationM } func addAnnotation(_ coordinate: CLLocationCoordinate2D, title: String, subTitle: String) -> TGAnnotation { let annotation: TGAnnotation = TGAnnotation() annotation.coordinate = coordinate annotation.title = title annotation.subtitle = subTitle mapView.addAnnotation(annotation) return annotation } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {// camera()// snap() poi() } func poi(){ let request: MKLocalSearchRequest = MKLocalSearchRequest() request.naturalLanguageQuery = "小吃" request.region = mapView.region let search: MKLocalSearch = MKLocalSearch(request: request) search.start { (response: MKLocalSearchResponse?, error: Error?) in if error == nil { let items = response!.mapItems for item in items { self.addAnnotation(item.placemark.coordinate, title: item.name ?? "", subTitle:item.phoneNumber ?? "") print(item.name ?? "") } } } } func snap() { let option: MKMapSnapshotOptions = MKMapSnapshotOptions() option.region = mapView.region option.mapType = .satellite option.size = CGSize(width: 1000, height: 1000) let snapShoter = MKMapSnapshotter(options: option) snapShoter.start { (shot: MKMapSnapshot?, error: Error?) in if error == nil { let image = shot?.image let data = UIImagePNGRepresentation(image!) try? data?.write(to: URL(fileURLWithPath: "/Users/targetcloud/Desktop/snap.png"), options: [.atomic]) } } } func camera() {//3D视图 let center = mapView.centerCoordinate // 参数: 需要看的位置、 从哪个地方看、 站多高看 let camera: MKMapCamera = MKMapCamera(lookingAtCenter: center, fromEyeCoordinate: CLLocationCoordinate2DMake(center.latitude, center.longitude + 0.1), eyeAltitude: 500) mapView.setCamera(camera, animated: true) }}class TGAnnotation: NSObject, MKAnnotation { var coordinate: CLLocationCoordinate2D = CLLocationCoordinate2DMake(0, 0) var title: String? var subtitle: String?}extension ViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { let annotation = view.annotation if #available(iOS 9.0, *) { (view.detailCalloutAccessoryView as! UILabel).text = (annotation?.subtitle)! } print("选中了\(annotation?.subtitle)") } func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) { let annotation = view.annotation print("取消选中了\(annotation?.subtitle)") } func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let iden = "item" var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: iden) if annotationView == nil { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: iden) } annotationView?.annotation = annotation annotationView?.image = UIImage(named: "category_1") annotationView?.centerOffset = CGPoint(x: 0, y: 0) annotationView?.canShowCallout = true annotationView?.calloutOffset = CGPoint(x: -10, y: 10) if #available(iOS 9.0, *) { let detailLabel : UILabel = UILabel() detailLabel.frame = CGRect(x: 0, y: 0, width: 100, height: 40) detailLabel.numberOfLines = 0 annotationView?.detailCalloutAccessoryView = detailLabel } annotationView?.isDraggable = true return annotationView }}
0 0
- swift地图定位(十六)poi及其他
- swift地图定位(二十)百度地图的使用(POI)
- swift 地图定位(一)
- swift 地图定位(三)
- swift 地图定位(四)
- 仿去哪网酒店的地图:POI、定位、国际地图、导航、marker及其自定义infowindow
- swift 地图定位(五)指南针
- swift 地图定位(六)区域监听
- swift地图定位(十五)使用MKUserTrackingBarButtonItem
- swift地图定位(十九)集成百度地图
- 地图(定位、POI、地理编码……)
- swift地图定位(九)github-LocationManager的使用
- swift地图定位(十一)MapKit初使用
- swift地图定位(十二)大头针的基本使用
- swift地图定位(十三)大头针系统视图
- swift地图定位(十四)使用 MKAnnotationView自定义大头针视图
- swift地图定位(十七)使用系统APP导航
- 百度地图的定位和poi搜索
- 数组作为函数参数
- 【UOJ78】二分图最大匹配
- ubuntu下 C++ 函数创建目录
- 判断循环链表是否有环
- 平均数 题解【二分+求逆序对】
- swift地图定位(十六)poi及其他
- 一些小模板总结
- 【C#】C#实现嵌入式窗体(弹出的子窗体在父窗体内)
- 面试与简历那些事
- 取整小数
- Ubuntu 16.10 64位安装WPS
- 史上最全Java学习视频下载地址分享
- 水平/垂直滚动联动
- 123. Best Time to Buy and Sell Stock III