//百度引入 <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script> <script type="text/javascript" src="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.js"></script> <script type="text/javascript" src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js"></script> <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchControl/1.4/src/SearchControl_min.css" /> <link href="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.css" rel="stylesheet" type="text/css" /> /*处理地图开始*/ .BMapLib_cityTab{ display: none !important; } .anchorBL{ display: none !important; } #map_container{ height: 8rem !important; } #searchBox{ position: fixed; bottom: 3rem; z-index: 1; } .BMapLib_sc_t input{ background: #fff; position: absolute; top: 0; left: 0; } .BMap_stdMpCtrl div{ display: none1; } #map_container{height:80%; border: 1px solid #999;height:400px;height: 11.65rem !important;} .BMap_cpyCtrl{display: none!important;}/*隐藏百度地图版权*/ @media print{ #notes{display:none} #map_container{margin:0} } /*处理地图结束*/ //必须添加,处理地图 <div id="map_container"></div> <div id="searchBox"></div> 添加input弹框,默认 <script type="text/javascript"> window.onload = function(){ $(".BMapLib_sc_b0").click(alert(123)); }; </script> //直接使用手机模板 <script> var kk=document.documentElement.clientWidth; if(kk>750){ kk=750 } document.documentElement.style.fontSize=kk/7.5+"px" </script> //百度处理地图 <script type="text/javascript"> // 创建地图对象并初始化 var mp = new BMap.Map("map_container",{ enableHighResolution: true //是否开启高清 }); var point = new BMap.Point(116.404, 39.915); mp.centerAndZoom(point, 14); //初始化地图 mp.enableInertialDragging(); //开启关系拖拽 mp.enableScrollWheelZoom(); //开启鼠标滚动缩放 // 添加定位控件 var geoCtrl = new BMap.GeolocationControl({ showAddressBar : true //是否显示 , enableAutoLocation : false //首次是否进行自动定位 , offset : new BMap.Size(0,25) //, locationIcon : icon //定位的icon图标 }); //监听定位成功事件 geoCtrl.addEventListener("locationSuccess",function(e){ console.log(e); }); //监听定位失败事件 geoCtrl.addEventListener("locationError",function(e){ console.log(e); }); // 将定位控件添加到地图 mp.addControl(geoCtrl); //检索类型 var type = ""; type = LOCAL_SEARCH ; //周边检索 //type = TRANSIT_ROUTE; //公交检索 //type = DRIVING_ROUTE; //驾车检索 //创建鱼骨控件 var navCtrl = new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_LEFT //设置鱼骨控件的位置 }); // 将鱼骨添加到地图当中 mp.addControl(navCtrl); //创建检索控件 var searchControl = new BMapLib.SearchControl({ container : "searchBox" //存放检索控件的容器 , map : mp //检索的关联地图 , type : type //检索类型 }); document.getElementById("selectType").onchange = function () { searchControl.setType(this.value); }; //添加路况控件 var ctrl = new BMapLib.TrafficControl({ showPanel: false //是否显示路况提示面板 }); mp.addControl(ctrl); ctrl.setAnchor(BMAP_ANCHOR_TOP_RIGHT); </script>