function initGDMap() { console.log('初始化地图'); var center =[22.538184,113.95148]; var map = new AMap.Map('container', { center:center, zoom:11 }); var placeSearch = new AMap.PlaceSearch({ map: map }); //构造地点查询类 var autoOptions = { input: "dw_position" }; var auto = new AMap.Autocomplete(autoOptions); AMap.event.addListener(auto, "select", select);//注册监听,当选中某条记录时会触发 function select(e) { placeSearch.setCity(e.poi.adcode); placeSearch.search(e.poi.name); //关键字查询查询 console.log(e,'eeeeee'); //修改输入框内容 document.getElementsByName('dw_position')[0].value = e.poi.name; document.getElementsByName('district')[0].value = e.poi.district; //修改经纬度记录 document.getElementsByName('lng_lat')[0].value = e.poi.location.lat+','+e.poi.location.lng; } } initGDMap();
<tr> <td style="text-align:right;">定位地址:<br/></td> <td colspan="3"><input class="inputs" type="text" name="dw_position" id="dw_position"> <input class="inputs" type="text" name="lng_lat" id="lng_lat"> <input class="inputs" type="text" name="district" id="district"></td> </tr> <tr> <td colspan="3"> <div id="container" style="width:610px;height:200px;"></div> </td> </tr>