日期:2014-05-16 浏览次数:20396 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>北京市海淀区地图信息</title> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.1&services=true"> </script> </head> <body> <form name="bjmap" action="map_test.html" method="post"> <input type="text" name="address" width="300px" value="海淀区学院路30号院" onfocus="this.value=''" /> <input type="submit" name="submit" value="查询" onclick="selectAddr()" /> </form> <div style="width:600px;height:500px;border:1px solid gray" id="container"></div> <script type="text/javascript"> function selectAddr(){ var adr = document.bjmap.address.value; alert("adr-2-->>"+adr); var mapObj = new BMap.Map("container"); // 创建Map实例 var point = new BMap.Point(116.404, 39.915); // 创建点坐标 //mapObj.centerAndZoom(point,13); // 初始化地图,设置中心点坐标和地图级别。 mapObj.enableScrollWheelZoom(); // 启用滚轮放大缩小。 mapObj.enableKeyboard(); // 启用键盘操作。 //添加多个控件 mapObj.addControl(new BMap.NavigationControl()); mapObj.addControl(new BMap.ScaleControl()); mapObj.addControl(new BMap.OverviewMapControl()); // 添加实时路况控件 mapObj.addControl(new BMap.TrafficControl()); //地址查询 mapObj.centerAndZoom(new BMap.Point(116.404, 39.915), 16); var local = new BMap.LocalSearch(mapObj, { renderOptions:{mapObj: mapObj} }); local.search(adr); } </script> </body> </html>