高德地图点击搜索触发输入提示

第一种
减少调用次数,不用每输入一次调用一次,输入完后再触发搜索
此方法为jsAPi,调用次数只有1000次
效果图:
在这里插入图片描述

![Alt](https://img-home.csdnimg.cn/images/20220524100510.png
dom结构

<div class="seach">
    <van-search
        show-action
        v-model="addressVal"
        placeholder="请输入地址搜索"
    >
        <template #action>
            <div @click="iptchange">搜索</div>
        </template>
    </van-search>
    <input
        style="display: none;"
        class="ipt"
        id="tipinput"
        placeholder="请输入地址搜索"
    />
</div>

事件

autoOptions() {
    var autoOptions = {
        input: 'tipinput'
    }
    var that = this
    window.AMap.plugin(['AMap.PlaceSearch', 'AMap.AutoComplete'], function () {
        var auto = new window.AMap.AutoComplete(autoOptions)
        auto.on('select', that.selectSite) // 注册监听,当选中某条记录时会触发
    })
    // 搜索框自动完成类
    this.auto = new window.AMap.AutoComplete({
        input: 'tipinput' // 使用联想输入的input的id
    })
    // 构造地点查询类
    this.placeSearch = new window.AMap.PlaceSearch({
        map: this.map
    })
    // 当选中某条搜索记录时触发
    this.auto.on('select', this.selectSite)
},
iptchange() {
	 var tipinput = document.getElementById('tipinput')
	 tipinput.value = this.addressVal
	 var event = new InputEvent('input')
	 tipinput.dispatchEvent(event)
	 this.autoOptions()
},

第二种
这种是web服务api,直接调用接口可实现输入提示,调用次数可达300000
在这里插入图片描述

iptchange() {
     var key = '自己申请的key'
     axios({
         methods: 'get',
         url: `https://restapi.amap.com/v3/assistant/inputtips?key=${key}&keywords=${this.addressVal}&city=重庆`
     }).then(res => {
        	console.log(res.data.tips)
     })
 },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值