天天看點

網站通用百度地圖調用示例,隻需填入座标和百度密鑰即可。内容可自己更換。

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
    <style type="text/css">
    body, html{width: %;height: %;margin:;font-family:"微軟雅黑";}
    #allmap {height:px;width:%;overflow: hidden; border:px solid #ccc; margin:px ;}
    #result {width:%;font-size:px;}
    dl,dt,dd,ul,li{
        margin:;
        padding:;
        list-style:none;
    }
    dt{
        font-size:px;
        font-family:"微軟雅黑";
        font-weight:bold;
        border-bottom:px dotted #000;
        padding:px  px px;
        margin:px ;
    }
    dd{
        padding:px   px;
    }
    li{
        line-height:px;
    }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=密鑰"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" /> 

    <div id="allmap">   
    </div>

<script type="text/javascript">
    // 百度地圖API功能
    var map = new BMap.Map('allmap');
    var poi = new BMap.Point(,);
    map.centerAndZoom(poi, );
    map.enableScrollWheelZoom();
    var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
                    '<img src="images/map.png" alt="" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>' +
                    '位址:XXXXX<br/>電話:XXXXX<br/>手機:XXX' 
                  '</div>';

    //建立檢索資訊視窗對象
    var searchInfoWindow = null;
    searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
            title  : "網站标題",      //标題
            width  : ,             //寬度
            height : ,              //高度
            panel  : "panel",         //檢索結果面闆
            enableAutoPan : true,     //自動平移
            searchTypes   :[
                BMAPLIB_TAB_SEARCH,   //周邊檢索
                BMAPLIB_TAB_TO_HERE,  //到這裡去
                BMAPLIB_TAB_FROM_HERE //從這裡出發
            ]
        });
    var marker = new BMap.Marker(poi); //建立marker對象
    marker.enableDragging(); //marker可拖拽
    marker.addEventListener("click", function(e){
        searchInfoWindow.open(marker);
    })
    map.addOverlay(marker); //在地圖中添加marker
    searchInfoWindow.open(marker);  
      // 添加帶有定位的導航控件
    var navigationControl = new BMap.NavigationControl({    
      anchor: BMAP_ANCHOR_TOP_LEFT,    // LARGE類型
      type: BMAP_NAVIGATION_CONTROL_LARGE, 
      enableGeolocation: true
    });
    map.addControl(navigationControl);      
</script>

<div class="clear"></div>
           

繼續閱讀