• swift


    1.xib 上的 3D效果 按钮

    2. 

    import UIKit
    //1.导入框架
    import MapKit
    
    class ViewController: UIViewController {
    
        @IBOutlet weak var mapView: MKMapView!
        
        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            //逆推第三部
            let center = mapView.centerCoordinate
            
            
            /*
             *  lookingAtCenter:可是中心
             *  fromEyeCoordinate:眼睛看到的坐标,从左还是从右边看
             *  eyeAltitude:眼睛高度, 海拔高度
             */
            //逆推第二部
            let camerea = MKMapCamera(lookingAtCenter: center, fromEyeCoordinate: CLLocationCoordinate2D(latitude: center.latitude + 0.1, longitude: center.longitude), eyeAltitude: 150)
            
            //逆推第一步
            mapView.setCamera(camerea, animated: true)
        }
    
    }
    

      

    2. 截图

    // MARK: - 截图
    extension ViewController{
        func snap(){
            
            /// 限制地图
            let option  = MKMapSnapshotter.Options()
            
            /// 截图区域
            option.region = mapView.region
            
            /// 截图的地图类型
            option.mapType = MKMapType.satellite
      
            /// 输入图片大小
            option.size = CGSize( 1000, height: 1000)
            
            /// 创建截图对象
            let snapShoter = MKMapSnapshotter(options: option)
            
            //开始截图
            snapShoter.start { (shot, err) in
                if err == nil{
                    let img = shot?.image
                    let data = img?.pngData() as NSData?
                    data?.write(toFile: "/Users/apple/Desktop/test.png", atomically: true)
                }else{
                    print("error")
                }
            }
        }
    }
    

      

    3. 关键字搜索

    // MARK: - 本地搜索
    extension ViewController{
        func localSearch(){
            
            /// 创建一个请求
            let request : MKLocalSearch.Request = MKLocalSearch.Request()
            
            /// 设置搜索关键字
            request.naturalLanguageQuery = "小吃"
            
            /// 设置检索的区域范围
            request.region = mapView.region
            
            /// 创建搜索对象
            let search = MKLocalSearch(request: request)
            
            /// 搜索对象:注意 默认结果最多10个
            search.start { (response, err) in
                if err == nil {
                    // 响应对象 MKLocalSearchResponse
                    //  里面存储着检索出来的"地图项"
                    // 每个地图项 中 有包含位置信息, 商家信息等
                    let items = response!.mapItems
                    for item in items {
                        if let name = item.name{
                            print(name)
                        }
                    }
                }
            }
        }
    }
    

      

  • 相关阅读:
    常用工具篇(二)死链接扫描工具–Xenu
    基于python的性能测试工具–locust
    AppServ 8.0 的php 5.6 切换到 php7.0 方法
    toString()和toLocaleString() 的区别
    解决Nginx无法重启问题
    解决 AppServ8.0 安装好之后数据库登陆不上的问题
    TCP/IP 协议
    pc端登陆多个微信
    阿里云服务器创建宝塔面板教程
    轻松免费将你的家庭版windows10升级到windows10专业版
  • 原文地址:https://www.cnblogs.com/qingzZ/p/10113227.html
Copyright © 2020-2023  润新知