我用的是天地图里的api,因为是使用leaflet框架混合天地图开发的,功能也不是特别完善,也不是最优方案,有机会学习一下leaflet框架中定位搜索的api
// 搜索地名
searchMap() {
console.log(document.getElementById('boox').val, this.searchName, 'searchName')
this.poisArr = [] //地方名称
console.log('触发搜索')
this.isShow = true
this.clearAll()
const _that = this
let addresServer = `http://api.tianditu.gov.cn/v2/search?postStr={"keyWord":"${ _that.searchName}","level":12,"mapBound":"116.02524,39.83833,116.65592,39.99185","queryType":1,"start":0,"count":10}&type=query&tk=天地图key`
axios
.get(addresServer)
.then(res => {
this.rt = res
if (res.status == 200) {
switch (res.data.resultType) {
case 1:
//解析点数据结果
this.rt = res.data.pois
this.pois(this.rt)
break
case 2:
//解析推荐城市
this.rt = res.data.statistics
this.statistics(this.rt)
break
case 3:
//解析行政区划边界
this.rt = res.data.area
this.area(this.rt)