900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > html5 直接获取当前位置 HTML5调用百度地图API获取当前位置并直接导航目的地的方法...

html5 直接获取当前位置 HTML5调用百度地图API获取当前位置并直接导航目的地的方法...

时间:2022-07-12 02:54:24

相关推荐

html5 直接获取当前位置 HTML5调用百度地图API获取当前位置并直接导航目的地的方法...

//$ak=2051409c59b8d558c7e6bbd0c5c62ffd

body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}

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);//地图中心点移到当前位置

var latCurrent = r.point.lat;

var lngCurrent = r.point.lng;

//alert('我的位置:'+ latCurrent + ',' + lngCurrent);

location.href="http://api./direction?origin="+latCurrent+","+lngCurrent+"&destination=39.89778,116.709684&mode=driving&region=北京&output=html";

}

else {

alert('failed'+this.getStatus());

}

},{enableHighAccuracy: true})

map.addOverlay(marker);

var licontent="健龙森羽毛球馆

";

licontent+="地址:北京市通州区滨河中路108号

";

licontent+="电话:(010)81556565 / 6969

";

var opts = {

width : 200,

height: 80,

};

var infoWindow = new BMap.InfoWindow(licontent, opts);

marker.openInfoWindow(infoWindow);

marker.addEventListener('click',function(){

marker.openInfoWindow(infoWindow);

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。