<!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>Jason-张百万正在为您开启导航APP ,获取当前位置并导航到目的地</title><script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=这里是你的百度地图key"></script><script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script><!--调用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"> // 读取url 传值 fid=XXX //通过url传值来进行一KEY导航 function GetQueryString(title) { var reg = new RegExp("(^|&)" + title + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } // 调用方法 // alert(GetQueryString("title")); // alert(GetQueryString("jingdu")); // alert(GetQueryString("weidu")); var jingweidu= GetQueryString("jingdu") + ',' + GetQueryString("weidu"); var map = new BMap.Map("allmap"); var point = new BMap.Point(jingweidu); map.centerAndZoom(point, 20); map.enableScrollWheelZoom(); var myIcon = new BMap.Icon("/assets/img/center.gif", 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);//地图中心点移到当前位置 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="+jingweidu+"&mode=driving®ion=哈尔滨市&output=html"; } else { alert('failed' + this.getStatus()); } }, { enableHighAccuracy: true }) map.addOverlay(marker); var licontent = "<b>正在为您开启导航APP 将根据您的GPS位置载入一健导航</b>"; // licontent += "<span><strong>地址:</strong>哈尔滨市禧龙五金市场东区2街区A号</span><br>"; // licontent += "<span><strong>电话:</strong>1555555555</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>
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。