1.首先判断是安卓还是IOS
2.判断手机中百度地图和高德地图是否已经安装
3.已安装,则调用相应的地址
var u = navigator.userAgent
var scheme = ''
// IOS地图跳转
if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
if(plus.runtime.isApplicationExist({pname:'com.autonavi.minimap',action:'iosamap://'})){ // 判断高德地图 是否安装
scheme = `iosamap://navi?sourceApplication=amap&lat=${i.lat}&lon=${i.lon}&dev=1&style=2`
} else if(plus.runtime.isApplicationExist({pname:'com.baidu.BaiduMap',action:'baidumap://'})){
scheme = `baidumap://map/direction?&destination=${i.lat},${i.lon}&coord_type=bd09ll&mode=driving&src=ios.baidu.openAPIdemo`
// console.log(scheme, 'scheme')
}else {
this.$message.error('请安装高德地图或百度地图')
}
}
// 安卓手机地图跳转
if (u.indexOf('Android') > -1) {
if(plus.runtime.isApplicationExist({pname:'com.autonavi.minimap',action:'iosamap://'})){ // 判断高德地图 是否安装
scheme = `androidamap://navi?sourceApplication=amap&lat=${i.lat}&lon=${i.lon}&dev=1&style=2`
} else if(plus.runtime.isApplicationExist({pname:'com.baidu.BaiduMap',action:'baidumap://'})){ // 判断百度地图是否安装
scheme = `bdapp://map/direction?destination=${i.lat},${i.lon}&coord_type=bd09ll&mode=driving&src=andr.baidu.openAPIdemo`
} else {
// scheme = `https://apis.map.qq.com/uri/v1/routeplan?type=drive&to=${i.enterprisename}}&tocoord=${i.lat},${i.lon}&policy=1&referer=plus.com.netintech.szlsjprod`
this.$message.error('请安装高德地图或百度地图')
}
}
window.location.href = scheme
参考地址:
百度URI API | 百度地图API SDK
高德:导航-iOS-开发指南-高德地图手机版 | 高德地图API
|