swift开发笔记28 使用系统自带地图

swift开发笔记28 使用系统自带地图,第1张

概述之前用的是百度地图,最后上架打包时提示百度的类库在swift中未完全编译,上架时必须取消自动bitcode功能。 于是打算用系统自带的地图取代原来的百度地图,其实也不需要该多少代码,百度地图的类名往往也有对应的系统地图类名,只是加了个“B”,例如: 多边形类:MKPolygon,在百度地图改成了:BMKPolygon。 首先去掉百度类库framework,加上系统地图类库MapKit.framew

之前用的是百度地图,最后上架打包时提示百度的类库在swift中未完全编译,上架时必须取消自动bitcode功能。

于是打算用系统自带的地图取代原来的百度地图,其实也不需要该多少代码,百度地图的类名往往也有对应的系统地图类名,只是加了个“B”,例如:

多边形类:MKpolygon,在百度地图改成了:BMKpolygon。

首先去掉百度类库framework,加上系统地图类库MapKit.framework:


去掉:baIDumap开头的这几个,以及百度要用,但是我需要的QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework等,


然后把项目目录下的百度文件删了。。。还有桥接文件里的几个头文件

然后定位跟踪和绘制矩形代码:

import UIKitimport MapKitimport CoreLocationclass BaIDuMapVIEwController: UIVIEwController,MKMapVIEwDelegate {        @IBOutlet weak var iosmap: MKMapVIEw!    var locationManager:CLLocationManager!    var centerx:Double?    var centery:Double?    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        iosmap.mapType = .Standard        iosmap.delegate = self        iosmap.showsBuildings = true        if CLLocationManager.locationServicesEnabled(){            iosmap.setUserTrackingMode(MKUserTrackingMode.Follow,animated: true)            self.locationManager=CLLocationManager()            locationManager.requestWhenInUseAuthorization()            locationManager.requestAlwaysAuthorization()        }        //上班地点区域        addploygon()    }    //跟踪用户位置 并调整地图范围    func mapVIEw(mapVIEw: MKMapVIEw,dIDUpdateUserLocation userLocation: MKUserLocation) {        if  let loc=userLocation.location {            self.iosmap.centerCoordinate = loc.coordinate            let vIEwregion=MKCoordinateRegionMakeWithdistance(loc.coordinate,10000,10000)            self.iosmap.setRegion(vIEwregion,animated: true)        }    }    //添加矩形区域    func addploygon (){        //左下        let x1 = 116.320313        let y1 = 39.906578         //右上        let x2 = 116.340723        let y2 = 39.91869          // 添加多边形覆盖物        var coords = [CLLocationCoordinate2D]()        coords.append(CLLocationCoordinate2DMake(y1,x1))        coords.append(CLLocationCoordinate2DMake(y!,x2))        coords.append(CLLocationCoordinate2DMake(y2,x1))                let  polygon = MKpolygon(coordinates: &coords,count:  Int(coords.count))         self.iosmap.addOverlay(polygon)      }//矩形的样式func mapVIEw(mapVIEw: MKMapVIEw,rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {    if overlay is MKpolygon {        let polygonVIEw = mkpolygonrenderer(overlay: overlay)        polygonVIEw.strokecolor = UIcolor.redcolor()                return polygonVIEw    }    return MKOverlayRenderer()}}
总结

以上是内存溢出为你收集整理的swift开发笔记28 使用系统自带地图全部内容,希望文章能够帮你解决swift开发笔记28 使用系统自带地图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1078126.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存