I am applying it in WeChat to customize the menu. The menu is directly linked to this HTML5 page. After getting the current location, I set the destination in the page, so that after opening the page, I will directly enter the navigation page.
You can save one step by sending the location information first, then clicking OK and then exiting the navigation.
<!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 page directly calls Baidu Map API to obtain the current location and directly navigate to the destination</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><!--Call jQuery--> <style type=text/css> body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:Microsoft Yahei;} </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);//Move the map center point to the current position var latCurrent = r.point.lat; var lngCurrent = r.point.lng; //alert('My location:'+ latCurrent + ',' + lngCurrent); location.href=http://api.map.baidu.com/direction?origin=+latCurrent+,+lngCurrent+&destination=39.89778,116.709684&mode=driving®ion=Beijing&output=html; } else { alert('failed'+this .getStatus()); } },{enableHighAccuracy: true}) map.addOverlay(marker); var licontent=<b>Jianlongsen Badminton Hall</b><br>; licontent+=<span><strong>Address: </strong>No. 108, Binhe Middle Road, Tongzhou District, Beijing</strong> span><br>; licontent+=<span><strong>Tel:</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> SummarizeThe above is the implementation code of the HTML5 page introduced by the editor to directly call Baidu Map API to obtain the current location and direct navigation destination. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply in time. Everyone's. I would also like to thank everyone for your support of the VeVb martial arts website!