美文网首页
打开第三方地图应用

打开第三方地图应用

作者: 王玺__boy | 来源:发表于2017-07-03 22:41 被阅读0次

本文转自自:http://blog.csdn.net/riven_wn/article/details/52912082

先看实现后的效果,会自动检测手机安装的第三方地图。

step 1 在info.plist 里添加URL Scheme

百度地图:baidumap://

高德地图:iosamap://

google地图:comgooglemaps://

腾讯地图:qqmap://

step 2 代码部分

[objc]view plaincopy

print?

func creatOptionMenu(){

optionMenu = UIAlertController(title:nil,message:nil,preferredStyle:.ActionSheet)

if(SHARE_APPLICATION.canOpenURL(NSURL(string:"qqmap://")!) ==true){

let qqAction = UIAlertAction(title:"腾讯地图",style:.Default,handler: {

(alert: UIAlertAction!) -> Void in

let urlString ="qqmap://map/routeplan?from=我的位置&type=drive&tocoord=\(self.centerLat),\(self.centerLng)&to=\(self.siteTitle)&coord_type=1&policy=0"

let url = NSURL(string:urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)

SHARE_APPLICATION.openURL(url!)

})

optionMenu.addAction(qqAction)

}

if(SHARE_APPLICATION.canOpenURL(NSURL(string:"iosamap://")!) ==true){

let gaodeAction = UIAlertAction(title:"高德地图",style:.Default,handler: {

(alert: UIAlertAction!) -> Void in

let urlString ="iosamap://navi?sourceApplication=app名&backScheme=iosamap://&lat=\(self.centerLat)&lon=\(self.centerLng)&dev=0&style=2"

let url = NSURL(string:urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)

SHARE_APPLICATION.openURL(url!)

})

optionMenu.addAction(gaodeAction)

}

if(SHARE_APPLICATION.canOpenURL(NSURL(string:"comgooglemaps://")!) ==true){

let googleAction = UIAlertAction(title:"Google地图",style:.Default,handler: {

(alert: UIAlertAction!) -> Void in

let urlString ="comgooglemaps://?x-source=app名&x-success=comgooglemaps://&saddr=&daddr=\(self.centerLat),\(self.centerLng)&directionsmode=driving"

let url = NSURL(string:urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)

SHARE_APPLICATION.openURL(url!)

})

optionMenu.addAction(googleAction)

}

let appleAction = UIAlertAction(title:"苹果地图",style:.Default,handler: {

(alert: UIAlertAction!) -> Void in

let loc = CLLocationCoordinate2DMake(self.centerLat,self.centerLng)

let currentLocation = MKMapItem.mapItemForCurrentLocation()

let toLocation = MKMapItem(placemark:MKPlacemark(coordinate:loc,addressDictionary:nil))

toLocation.name=self.siteTitle

MKMapItem.openMapsWithItems([currentLocation,toLocation],launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: NSNumber(bool:true)])

})

optionMenu.addAction(appleAction)

if(SHARE_APPLICATION.canOpenURL(NSURL(string:"baidumap://")!) ==true){

let baiduAction = UIAlertAction(title:"百度地图",style:.Default,handler: {

(alert: UIAlertAction!) -> Void in

let urlString ="baidumap://map/direction?origin={{我的位置}}&destination=latlng:\(self.centerLat),\(self.centerLng)|name=\(self.siteTitle)&mode=driving&coord_type=gcj02"

let url = NSURL(string:urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)

SHARE_APPLICATION.openURL(url!)

})

optionMenu.addAction(baiduAction)

}

let cancelAction = UIAlertAction(title:"取消",style:.Cancel,handler: {

(alert: UIAlertAction!) -> Void in

})

optionMenu.addAction(cancelAction)

}

点击方法里,实现弹出

[objc]view plaincopy

print?

self.presentViewController(optionMenu,animated:true,completion:nil)

相关文章

  • iOS在应用内打开第三方地图

    比较常用的第三方地图有: 高德地图 百度地图 腾讯地图 Apple地图 在应用内打开外部第三方地图,可以打开外部地...

  • iOS在应用内打开第三方地图

    比较常用的第三方地图有: 高德地图 百度地图 腾讯地图 Apple地图 在应用内打开外部第三方地图,可以打开外部地...

  • 地图导航

    URI跳转方式地图导航的代码实践iOS调用第三方地图路线导航IOS实现应用内打开第三方地图app进行导航 高德 i...

  • iOS应用中打开第三方地图

    在项目中,遇到了应用中打开第三方地图的功能,网上的文章几乎清一色的打开第三方地图并且导航,但我的项目中不需要导航的...

  • 开发问题笔记(十三)

    目录 1.App内打开第三方地图进行导航 1.App内打开第三方地图进行导航 App内打开第三方地图进行导航;举例...

  • uniapp打开第三方地图

    打开第三方地图应用需传入latitude 和longitude ,name 直接上代码!!! toMapAPP(l...

  • 打开第三方地图应用

    本文转自自:http://blog.csdn.net/riven_wn/article/details/52912...

  • iOS调起地图(百度、高德、腾讯、苹果自带)

    下面分3种情况进行分析:1、用户没有安装第三方的地图,只有苹果自带的地图应用。2、用户安装一款第三方地图应用。3、...

  • 高德地图开发相关总结

    目录 1.坐标初始化方法2.打开第三方地图应用App进行导航及坐标转换3.地图最简单的定位及气泡图标展示4.地图路...

  • 地图开发相关总结

    目录 1.打开第三方地图应用App2.路径规划3.途经点 1.地图途经点开发(bbx司机端智能调度按顺序接送乘客)

网友评论

      本文标题: 打开第三方地图应用

      本文链接:https://www.haomeiwen.com/subject/kbazcxtx.html