<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5唤起百度地图APP示例</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <script src="https://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script> -->
<script src="https://api.map.baidu.com/api?v=3.0&ak=Z8cAFdyicwilBWmhuPrEGUzpt6a9w3fl"></script>
</head>
<body>
<script type="text/javascript">
// $(document).ready(function(){
//唤起百度地图
function openBaiduMap(lng, lat, address) {
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function (result) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var queryString = `origin=latlng:${result.point.lat},${result.point.lng}|name:我的位置&destination=latlng:${lat},${lng}|name:${address}&mode=driving&coord_type=bd09ll&src=com.mzwu.www`;
var app_url = `baidumap://map/direction?${queryString}`;
var web_url = `http://api.map.baidu.com/direction?${queryString}®ion=中国&output=html`;
//尝试唤起百度地图App
window.location.href = app_url;
//唤起失败打开Web版百度地图
var startTime = Date.now();
var count = 0;
var t = setInterval(function () {
if (++count < 30) {
return;
}
if (Date.now() - startTime > 800) {
clearInterval(t);
}
if (!(document.hidden || document.webkitHidden)) {
window.location.href = web_url;
}
}, 20);
window.onblur = function () {
clearInterval(t);
};
} else {
alert("获取不到定位,请检查手机设置!");
}
});
}
openBaiduMap(120.157749,30.263856,'西湖断桥');
// });
</script>
</body>