複製程式碼 程式碼如下: http://www.w3.org/1999/xhtml"> 依地址查詢經緯度 http://api.map.baidu.com/api?v=1.3">> 查詢的地址: 查詢結果(經緯度): style="position: absolute; margin-top:30px; width: 730px; height: 590px; top: 50; border: 1px solid gray; overflow:hidden;"> <br /> var map = new BMap.Map("container");<br /> map.centerAndZoom("徐州", 12);<br /> map.enableScrollWheelZoom(); //啟用滾輪放大縮小,預設為停用<br /> map.enableContinuousZoom(); //啟用地圖慣性拖曳,預設為停用<br /> map.addControl(new BMap.NavigationControl()); //新增預設縮放平移控制項<br /> map.addControl(new BMap.OverviewMapControl()); //新增預設縮略地圖控制項<br /> map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT })); //右下角,開啟<br /> var localSearch = new BMap.LocalSearch(map);<br /> localSearch.enableAutoViewport(); //允許自動調整窗體大小<br /> function searchByStationName() {<br /> map.clearOverlays();//清空原來的標註<br /> var keyword = document.getElementById("text_").value;<br /> localSearch.setSearchCompleteCallback(function (searchResult) {<br /> var poi = searchResult.getPoi(0);<br /> document.getElementById("result_").value = poi.point.lng "," poi.point.lat;<br /> map.centerAndZoom(poi.point, 13);<br /> var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 建立標註,為要查詢的地方對應的經緯度<br /> map.addOverlay(marker);<br /> var content = document.getElementById("text_").value "<br/><br/>經度:" poi.point.lng "<br/>緯度:" poi.point.lat;<br /> var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" content "");<br /> marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });<br /> // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳動的動畫<br /> });<br /> localSearch.search(keyword);<br /> } <br /> 以上就是程式碼的全部內容了,小夥伴們可以直接使用在專案中哦,不用跟我說謝謝,請叫我雷鋒大大~