zoukankan      html  css  js  c++  java
  • 百度地图

    <!DOCTYPE html>
    <html>
    
    	<head>
    		<meta charset="UTF-8">
    		<title>HTML5页面调用百度地图API,获取当前位置并导航到目的地</title>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=4qxErb13zcPupjUC8qGxNdj6gxy"></script>  
        <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script><!--调用jQuery-->
     
      <style type="text/css">
            body, html,#allmap { 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);//地图中心点移到当前位置
                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&region=北京&output=html";
     
            }
            else {
                alert('failed'+this.getStatus());
            }        
        },{enableHighAccuracy: true})
     
     
        map.addOverlay(marker);  
        var licontent="<b>健龙森羽毛球馆</b><br>";  
            licontent+="<span><strong>地址:</strong>北京市通州区滨河中路108号</span><br>";  
            licontent+="<span><strong>电话:</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>
    
    	</body>
    
    </html>
    
  • 相关阅读:
    Jar包管理规范
    Base64编码原理与应用
    MySQL 5.7.14安装说明,解决服务无法启动
    idea注册
    Oracle 如何对中文字段进行排序
    SVN错误:Attempted to lock an already-locked dir
    排序算法
    设计模式
    分层
    阿里云
  • 原文地址:https://www.cnblogs.com/gxywb/p/10071008.html
Copyright © 2011-2022 走看看