我是應(yīng)用在微信中,自定義菜單,菜單直接鏈接到這個(gè)HTML5頁(yè)面,獲取當(dāng)前位置后,頁(yè)面中定好目的地,這樣打開(kāi)頁(yè)面后直接進(jìn)入導(dǎo)航頁(yè)面
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>HTML5頁(yè)面直接調(diào)用百度地圖API,獲取當(dāng)前位置,直接導(dǎo)航目的地</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=wDYEcxgRRheZwyC9jpN1Tt7fzr2zjosZ"></script>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script><!--調(diào)用jQuery-->
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微軟雅黑";}
</style>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.709684,39.89778);
map.centerAndZoom(point, 16);
map.enableScrollWheelZoom();
var myIcon = new BMap.Icon("myicon.png",new BMap.Size(30,30),{
anchor: new BMap.Size(10,10)
});
var marker=new BMap.Marker(point,{icon: myIcon});
map.addOverlay(marker);
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);//地圖中心點(diǎn)移到當(dāng)前位置
var latCurrent = r.point.lat;
var lngCurrent = r.point.lng;
//alert('我的位置:'+ latCurrent + ',' + lngCurrent);
location.href="http://api.map.baidu.com/direction?origin="+latCurrent+","+lngCurrent+"&destination=39.89778,116.709684&mode=driving®ion=北京&output=html";
}
else {
alert('failed'+this.getStatus());
}
},{enableHighAccuracy: true})
map.addOverlay(marker);
var licontent="<b>健龍森羽毛球館</b><br>";
licontent+="<span><strong>地址:</strong>北京市通州區(qū)濱河中路108號(hào)</span><br>";
licontent+="<span><strong>電話(huà):</strong>(010)81556565 / 6969</span><br>";
var opts = {
width : 200,
height: 80,
};
var infoWindow = new BMap.InfoWindow(licontent, opts);
marker.openInfoWindow(infoWindow);
marker.addEventListener('click',function(){
marker.openInfoWindow(infoWindow);
});
</script>
以上所述是小編給大家介紹的HTML5頁(yè)面直接調(diào)用百度地圖API獲取當(dāng)前位置直接導(dǎo)航目的地的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!