<style> #baidumap { width: 100%; height: 300px; margin-top: 10px; } #map_result { width: 100%; }</style><div id="baidumap"> </div> <div id="map_result"> </div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=AK"></script> <script type="text/javascript"> var map = new BMap.Map("baidumap"); map.centerAndZoom(new BMap.Point(121.451637, 28.671701), 16); map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用 map.enableContinuousZoom(); //启用地图惯性拖拽,默认禁用 getAddress(); function getAddress() { var address = $("input[name=Address]").val() var myGeo = new BMap.Geocoder(); // 将地址解析结果显示在地图上,并调整地图视野 myGeo.getPoint(address, function (point) { if (point) { map.centerAndZoom(point, 16); var marker = new BMap.Marker(point); map.addOverlay(marker); var label = new BMap.Label("定位点,如确定该位置,请点击", { offset: new BMap.Size(20, -10) }) marker.setLabel(label); var local = new BMap.LocalSearch(map, { renderOptions: { map: map, panel: "map_result" } }); local.search(address) } else { alert("您选择地址没有解析到结果!"); } }, "台州市椒江开元大酒店牡丹厅"); } function changeLAT(e) { alert(e.point.lng + ", " + e.point.lat); $("input[name=Longitude]").val(e.point.lng); $("input[name=Latitude]").val(e.point.lat); } map.addEventListener("click", changeLAT); </script>
时间: 2024-10-25 19:56:06