日期:2014-05-16 浏览次数:20352 次
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>本地搜索的数据接口</title> <script src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194&v=1.1&services=true" type="text/javascript"></script> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> </head> <body > <div style="width:520px;height:340px;border:1px solid gray" id="container"></div> <input id="log" type="text" /> <input id="Button1" type="button" onclick="sbutton()" value="搜索" /><input id="Text1" type="text" /> <script type="text/javascript"> var map = new BMap.Map("container"); map.centerAndZoom(new BMap.Point(120.165941, 30.294973), 11); function search() { var options = { onSearchComplete: function (results) { // if (local.getStatus() == BMAP_STATUS_SUCCESS) { try { document.getElementById("log").value = results.getPoi(0).point.lng; } catch (e) { return 0; } // } } }; var local = new BMap.LocalSearch(map, options); local.search(document.getElementById("Text1").value); } function sbutton() { search(); alert(document.getElementById("log").value) } </script> </body> </html>