H5 实现高德 百度 地图导航 可唤醒app
记住在引入高德地图
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=高德key&plugin=AMap.Driving&plugin=AMap.ToolBar"></script>
//转百度坐标
changeBd(gg_lng, gg_lat) {
var X_PI = (Math.PI * 3000.0) / 180.0
var x = gg_lng,
y = gg_lat
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI)
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI)
var bd_lng = z * Math.cos(theta) + 0.0065
var bd_lat = z * Math.sin(theta) + 0.006
return {
lat: bd_lat,
lng: bd_lng,
}
},
//导航
goMap(type) {
var drivingOption = {
policy: AMap.DrivingPolicy.LEAST_DISTANCE, // 其它policy参数请参考 https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingPolicy
ferry: 1, // 是否可以使用轮渡
province: "皖" // 车牌省份的汉字缩写
};
this.driving = new AMap.Driving(drivingOption);
//0百度//1高德
if (type == 0) {
//godata目标地点名称
let startBd = this.changeBd(this.startLng, this.startLat);
let endBd = this.changeBd(this.endLng, this.endLat);
location.href = `https://api.map.baidu.com/direction?origin=latlng:${startBd.lat},${startBd.lng}|name:我的位置&destination=latlng:${endBd.lat},${endBd.lng}|name:${this.godata}&mode=driving®ion=合肥&output=html&src=yourCompanyName|yourAppName`;
// console.log(href);
} else {
this.driving.search(
[this.startLng, this.startLat],
[this.endLng, this.endLat],
(status, result) => {
this.driving.searchOnAMAP({
origin: result.origin,
destination: result.destination
});
}
);
}
},