调用苹果地图、百度地图、高德地图导航(不需要集成sdk)
来源:互联网 发布:python实例教程 编辑:程序博客网 时间:2024/05/16 15:16
最近在研究地图,所以就简单写了一个小 demo,给大家分享一下如何不集成SDK就能调用第三方地图app,这里只介绍苹果自带地图、百度地图和高德地图的调用!其中还简单介绍了app定位功能,希望能给初学的开发者带来一点帮助!(swift)
import MapKitclass MapViewController: UIViewController,CLLocationManagerDelegate { /** 位置管理器 */ var locationManager : CLLocationManager = CLLocationManager() var myLocation : CLLocationCoordinate2D! override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self locationManager.requestWhenInUseAuthorization()//询问是否获取当前位置 openLocationService() // Do any additional setup after loading the view. } /** CLLocationManagerDelegate */ func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let currentLatitude = locations.last?.coordinate.latitude let currentLongitude = locations.last?.coordinate.longitude print(currentLatitude) print(currentLongitude) myLocation = locations.first?.coordinate //停止更新位置(如果定位服务不需要实时更新的话,那么应该停止位置的更新) locationManager.stopUpdatingLocation() } /** 目标位置 */ func getGoalLocation() -> CLLocationCoordinate2D { return CLLocationCoordinate2DMake(22.648838,114.026178) } //苹果地图 @IBAction func openAppleMapAction(sender: UIButton) { let currentLocationItem = MKMapItem.mapItemForCurrentLocation() let toLocationItem = MKMapItem.init(placemark: MKPlacemark.init(coordinate: getGoalLocation(), addressDictionary: nil)) toLocationItem.name = "大浪" MKMapItem.openMapsWithItems([currentLocationItem,toLocationItem], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving , MKLaunchOptionsShowsTrafficKey: true]) } //百度地图 @IBAction func openBMKMapAction(sender: UIButton) { if application.canOpenURL(NSURL.init(string: "baidumap://map/")!) { let urlString = "baidumap://map/direction?origin=latlng:\(22.6199163368547),\(114.018015580424)|name:我的位置&destination=latlng:\(getGoalLocation().latitude),\(getGoalLocation().longitude)|name:大浪&mode=driving" ["name":"百度地图","url":urlString] application.openURL(NSURL.init(string: urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.init(charactersInString: "`#%^{}\"[]|\\<> ").invertedSet)!)!) }else{ application.openURL(NSURL.init(string: "https://itunes.apple.com/cn/app/bai-du-tu-shou-ji-tu-lu-xian/id452186370?mt=8")!) } } //高德地图 @IBAction func openAMapAction(sender: UIButton) { if application.canOpenURL(NSURL.init(string: "iosamap://")!) { let urlString = "iosamap://navi?sourceApplication=充电桩&backScheme=applicationScheme&poiname=fangheng&poiid=BGVIS&lat=\(getGoalLocation().latitude)&lon=\(getGoalLocation().longitude)&dev=0&style=3" ["name":"高德地图","url":urlString] application.openURL(NSURL.init(string: urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.init(charactersInString: "`#%^{}\"[]|\\<> ").invertedSet)!)!) }else{ application.openURL(NSURL.init(string: "https://itunes.apple.com/cn/app/gao-tu-zhuan-ye-shou-ji-tu/id461703208?mt=8")!) } } /** 开启定位服务 */ func openLocationService() { if CLLocationManager.locationServicesEnabled() { if CLLocationManager.authorizationStatus() == .AuthorizedAlways || CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse { self.locationManager.distanceFilter = kCLDistanceFilterNone//任何的移动都进行重新定位 //设置定位的精准度,一般精准度越高,越耗电(这里设置为精准度最高的,适用于导航应用) self.locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation self.locationManager.startUpdatingLocation() }else{ UIAlertController.showAlert(self, title: "定位服务已关闭", message: "请在“设置” > “隐私”中打开“定位服务”来允许“充电桩”使用您的当前位置", cancelButtonTitle: "好", okButtonTitle: "设置", okHandler: { (alert) in application.openURL(NSURL.init(string: "prefs:root=LOCATION_SERVICES")!) }) } } }
这样就已经完成了,就能调起百度地图了吗?不行,到这里我们还是不能调用,原因是在iOS9.0之后我们需要在info文件中配置一些东西,就像我们做分享的时候需要添加白名单一样
这样我们就能调起百度地图地图完成导航了。。。
1 0
- 调用苹果地图、百度地图、高德地图导航(不需要集成sdk)
- 调用高德地图,百度地图,腾讯地图,苹果地图路线规划(无需集成SDK)
- IOS 地图导航(其中包括苹果地图、百度地图、高德地图、谷歌地图)
- iOS 判断并使用 百度地图 高德地图 导航(使用URI,不集成sdk)
- iOS 判断并使用 百度地图 高德地图 导航(使用URI,不集成sdk)
- iOS 判断并使用 百度地图 高德地图 自带地图 导航(使用URI,不集成sdk)
- Android app调用第三方地图(百度地图,高德地图,谷歌地图)导航
- iOS 跳转到地图后导航(高德地图,百度地图,腾讯地图,苹果手机原生的地图)
- Android app调用第三方地图(百度地图,高德地图)导航
- App调用百度高德地图导航
- Unity3D 集成 高德地图SDK 地图
- 地图-导航(百度/高德)
- iOS开发——项目中的地图跳转(苹果地图,百度地图,高德地图)
- 集成百度地图、高德地图、腾讯地图sdk,谁优先选
- 集成百度地图sdk
- IOS 不集成SDK使用URL方式打开地图导航 谷歌 百度 高德
- 调用高德地图、百度地图客户端
- 调用高德导航,百度导航,腾讯地图
- @Validator验证
- 峻山电站1800调速器照片
- 第8课:彻底实战详解使用IDE开发Spark程序
- 解决Linux系统下(交叉)编译出现“cannot find -lxxx”的错误 (ubuntu)
- [MySQL]mac完全卸载MySQL
- 调用苹果地图、百度地图、高德地图导航(不需要集成sdk)
- windows下使用tftp工具下载文件到开发板(linux)
- 剑指Offer----扩展:0-1交换
- Android 单元测试
- RHEL5.1的TFTP服务器的安装
- MyBatis学习总结[2]-接口式调用
- centos6.5 安装kafka2.11
- 情感
- java 三大特性之继承