func mapGoWeb(type: Int) {
let longitudeS: String = viewM?.longitude ?? ""//经度
let latitudeS: String = viewM?.latitude ?? ""//纬度
let shop_nameS: String = viewM?.shop_name ?? ""//商家名称
var routeUrlS: String = ""
var openUrlS: String = ""
var downloadUrlS: String = ""
switch type {
case 1://高德
openUrlS = "iosamap://"
routeUrlS = "iosamap://path?sourceApplication=ios.blackfish.XHY&dlat=\(latitudeS)&dlon=\(longitudeS)&dname=\(shop_nameS)&style=2"
downloadUrlS = "itms-apps://itunes.apple.com/app/id461703208?mt=8"
case 2://百度
openUrlS = "baidumap://"
let tolocation = self.getBaiDuCoordinateByGaoDeCoordinate(coordinate: CLLocationCoordinate2D.init(latitude: Double(latitudeS)!, longitude: Double(longitudeS)!))
routeUrlS = "baidumap://map/direction?origin=我的位置&destination=latlng:\(tolocation.latitude),\(tolocation.longitude)|name:\(shop_nameS)&mode=driving&coord_type=bd09ll&src=net.zoneland.m.o2oa"
downloadUrlS = "itms-apps://itunes.apple.com/cn/app/id452186370?mt=8"
case 3://腾讯
openUrlS = "qqmap://"
routeUrlS = "qqmap://map/routeplan?type=drive&from=我的位置&to=\(shop_nameS)&tocoord=\(latitudeS),\(longitudeS)&policy=1"
downloadUrlS = "itms-apps://itunes.apple.com/app/id481623196?mt=8"
case 4://苹果
let currentLocation = MKMapItem.forCurrentLocation()
let tolocation = MKMapItem.init(placemark: MKPlacemark.init(coordinate: CLLocationCoordinate2D.init(latitude: Double(latitudeS)!, longitude: Double(longitudeS)!)))
tolocation.name = shop_nameS
let options = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
MKMapItem.openMaps(with: [currentLocation,tolocation], launchOptions: options)
return
default: break
}
guard !routeUrlS.isEmpty else {
return
}
if UIApplication.shared.canOpenURL(openUrlS.url!) {
let url: URL = routeUrlS.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)?.url ?? URL(fileURLWithPath: "")
UIApplication.shared.open(url, options: [:]) { (success) in
if (success) {
print("跳转url")
}else{
print("不能完成跳转")
}
}
} else {
UIApplication.shared.open(downloadUrlS.url!, options: [:]) { (success) in
if (success) {
print("跳转url")
}else{
print("不能完成跳转")
}
}
}
}
// 高德经纬度转为百度地图经纬度
// 百度经纬度转为高德经纬度,减掉相应的值就可以了。
func getBaiDuCoordinateByGaoDeCoordinate(coordinate:CLLocationCoordinate2D) -> CLLocationCoordinate2D {
return CLLocationCoordinate2DMake(coordinate.latitude + 0.006, coordinate.longitude + 0.0065)
}
iOS开发笔记-141: swift5-跳转第三方导航app导航
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目里遇到根据经纬度跳转第三方导航的需求,在网上找了一下,发现都是千篇一律的文章,而且不能正确显示目的地地址,无果...