浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。

WebAPI文档全面上新

新增示例代码、在线运行等功能,帮助您实现快速接入,前往体验吧!

体验新版
与JavaScript API结合使用的示例

本示例是使用JavaScript API制作一张动态地图,在天安门添加标注,且提供最简单的信息窗口,同时使用URI API,构造一条简单的URL,调起PC端百度地图提供公交,驾车换乘检索服务。具体代码如下:

<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>JSAPI与URLAPI结合示例</title>  
<script type="text/javascript" src="https://api.map.baidu.com/api?v=1.5&ak=2b866a6daac9014292432d81fe9b47e3"></script>  
<script src="http://d1.lashouimg.com/static/js/release/jquery-1.4.2.min.js" type="text/javascript"></script>  
<style type="text/css">  
html,body{  
    width:400px;  
    height:300px;
    margin:0;
    overflow:hidden;  
    }
</style>  
</head>  
<body></body>  
</html>  
<script type="text/javascript">  
    var map = new BMap.Map("container");  
    map.centerAndZoom(new BMap.Point(116.403884,39.914887), 13);  
    map.enableScrollWheelZoom();  
    var marker=new BMap.Marker(new BMap.Point(116.403884,39.914887));  
    map.addOverlay(marker);  
    var licontent="<b>天安门</b><br>";  
        licontent+="<span><strong>地址:</strong>北京市东城区天安门广场北侧</span><br>";  
        licontent+="<span><strong>电话:</strong>(010)63095718,(010)63095630</span><br>";  
        licontent+="<span class="\"input\"><strong></strong><input" class="\"outset\"" type=\"text\" name=\"origin\" value=\"北京站\"/><input class="\"outset-but\"" type=\"button\" value=\"公交\" onclick=\"gotobaidu(1)\" /><input class="\"outset-but\"" type=\"button\" value=\"驾车\"  onclick=\"gotobaidu(2)\"/><a class="\"gotob\"" href=\"url=\"https://api.map.baidu.com/direction?destination=latlng:"+marker.getPosition().lat+","+marker.getPosition().lng+"|name:天安门"+"®ion=北京"+"&output=html\" target=\"_blank\"></a></span>";
  
    var hiddeninput="<input type=\"hidden\" value=\""+'北京'+"\" name=\"region\" /><input type=\"hidden\" value=\"html\" name=\"output\" /><input type=\"hidden\" value=\"driving\" name=\"mode\" /><input type=\"hidden\" value=\"latlng:"+marker.getPosition().lat+","+marker.getPosition().lng+"|name:天安门"+"\" name=\"destination\" />";
  
    var content1 ="<form id=\"gotobaiduform\" action=\"https://api.map.baidu.com/direction\" target=\"_blank\" method=\"get\">" + licontent +hiddeninput+"</form>";
   
    var opts1 = { width: 300 };  
        
    var  infoWindow = new BMap.InfoWindow(content1, opts1);  
    marker.openInfoWindow(infoWindow);  
    marker.addEventListener('click',function(){
        marker.openInfoWindow(infoWindow);
    });  
      
    function gotobaidu(type)  
    {  
        if($.trim($("input[name=origin]").val())=="")  
        {  
            alert("请输入起点!");  
            return;  
        }else{  
            if(type==1)  
            {  
                $("input[name=mode]").val("transit");  
                $("#gotobaiduform")[0].submit();  
            }else if(type==2)  
            {      
                $("input[name=mode]").val("driving");          
                $("#gotobaiduform")[0].submit();  
            }  
        }  
    }     
</script>
与静态图片结合使用的示例

本示例是使用静态图API制作一张上海虹桥机场位置展示的静态地图图片,若用户点击此图片,便可进入PC端百度地图查看更多信息及交通换乘方案等。

实现代码如下:

<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

<title>静态图与URLAPI结合示例</title>    
<body>   
    <a href='https://api.map.baidu.com/geocoder?address=上海虹桥机场&output=html' target='_blank'> <img style="margin:2px" width="400" height="300" src="https://api.map.baidu.com/staticimage? 
        width=400&height=300&zoom=11&center=上海虹桥机场" />  
    </a>
</body>  
</html>  
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消