<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script>
function go(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(comeOn);
}else{
x.innerHTML="这个浏览器不支持定位。";
}
}
function comeOn(position){
window.location.href="http://api.map.baidu.com/direction?origin=
latlng:"+position.coords.latitude+","+position.coords.longitude+"|name:
我所在位置:&destination=句容葡萄采摘园&mode=driving®ion=江苏&output=
html&src=yourCompanyName|yourAppName";
}
</script>
</head>
<body>
<img src="../img/menu_daohang.png" class="daohang" onclick="go()"/>
</div>
</body>
</html>
为了适应ios版本,特意修改了。在微信端打开百度的网页导航。在其他浏览器直接打开百度地图的APP
<script>
function go() {
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var weixin = u.indexOf('MicroMessenger') > -1; //是否微信 (2015-01-22新增)
var webKit = u.indexOf('AppleWebKit') > -1;
//alert('是否是webKit:'+webKit);
//alert('是否是iOS:'+isiOS);
if (weixin) {
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398, 39.897445);
map.centerAndZoom(point, 12);
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function (r) {
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
// alert('您的位置:' + r.point.lng + ',' + r.point.lat);
window.location.href = "https://api.map.baidu.com/direction?origin=latlng:" + r.point.lat + "," + r.point.lng + "|name:我所在位置:&destination=合肥万达乐园&mode=driving®ion=江苏&output=html&src=yourCompanyName|yourAppName";
}
else {
alert('failed' + this.getStatus());
}
}, {enableHighAccuracy: true})
}
else {
if (isAndroid) {
window.location.href = "bdapp://map/navi?query=合肥万达乐园&type=BLK&src=webapp.navi.yourCompanyName.yourAppName"
}
else {
window.location.href = "baidumap://map/navi?query=合肥万达乐园&src=push&type=BLK&src=webapp.line.yourCompanyName.yourAppName"
}
}
}
</script>