css
#pickerBox {
position: absolute;
z-index: 9999;
top: 35px;
right: 30px;
width: 250px;
}
#pickerInput {
width: 250px;
padding: 5px 5px;
}
#poiInfo {
background: #fff;
}
.amap_lib_placeSearch .poibox.highlight {
background-color: #CAE1FF;
}
.amap_lib_placeSearch .poi-more {
display: none !important;
}
html
<!-- 搜索框开始 -->
<div id="pickerBox">
<input id="pickerInput" placeholder="输入关键字选取地点" />
<div id="poiInfo"></div>
</div>
<!-- 搜索框结束 -->
js
/*================ 地图搜索 开始 ================*/
AMapUI.loadUI(['misc/PoiPicker'], function (PoiPicker) {
var poiPicker = new PoiPicker({
city: '上海',
input: 'pickerInput'
});
//初始化poiPicker
poiPickerReady(poiPicker);
});
function poiPickerReady(poiPicker) {
window.poiPicker = poiPicker;
//选取了某个POI
poiPicker.on('poiPicked', function (poiResult) {
var source = poiResult.source,
poi = poiResult.item,
info = {
source: source,
id: poi.id,
name: poi.name,
location: poi.location.toString(),
address: poi.address
};
let newCenter = [poi.location.lng, poi.location.lat]
map.setCenter(newCenter);
map.setZoom(15)
});
}
/*================ 地图搜索 结束 ================*/