html代码
<el-col :span="24">
<el-form-item label="所在地址" prop="address">
<el-input
:disabled="!editValidate"
v-model="form.address"
></el-input>
<el-button
type="primary"
icon="el-icon-search"
size="mini"
@click="search()"
>搜索</el-button
>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="经度" >
<el-input readonly v-model="lng"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="纬度" >
<el-input readonly v-model="lat"></el-input>
</el-form-item>
</el-col>
<!-- 将地图隐藏-->
<el-col>
<div id="mapView" style="overflow: fragments">
</div>
</el-col>
js代码
//在打开dialog 的时候创建地图
this.$nextTick(() => {
this.initMap()
})
initMap() {
this.map = new window.AMap.Map('mapView', {
resizeEnable: true
});
},
//给按钮绑定的搜索事件
search () {
let that = this;
window.AMap.plugin('AMap.PlaceSearch', function () {
var autoOptions = {
city: '全国',
map: that.map,
pageSize: 1,
pageIndex: 1,
autoFitView: false
};
var placeSearch = new window.AMap.PlaceSearch(autoOptions);
placeSearch.search(that.form.address, function (status, result) {
if (status == 'complete') {
if (result.poiList.pois.length > 0) {
let lng = result.poiList.pois[0].location.lng;
let lat = result.poiList.pois[0].location.lat;
console.log(lng,lat)
that.$nextTick(() => {
that.lng=lng
that.lat=lat
// that.$set(that.form,'lng',lng)
// that.$set(that.form,'lat',lat)
})
}
}
});
});
},