免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

怎么在vue中使用BMap百度地圖實現一個即時搜索功能-創新互聯

怎么在vue中使用BMap百度地圖實現一個即時搜索功能?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

成都創新互聯公司是專業的廣陽網站建設公司,廣陽接單;提供做網站、網站制作,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行廣陽網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!Vue的優點

Vue具體輕量級框架、簡單易學、雙向數據綁定、組件化、數據和結構的分離、虛擬DOM、運行速度快等優勢,Vue中頁面使用的是局部刷新,不用每次跳轉頁面都要請求所有數據和dom,可以大大提升訪問速度和用戶體驗。

具體內容如下

首先去百度開發者申請一個key

然后將key引入到項目的 index.html:

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的key"></script>

下面是組件代碼:

<template>
 <div id="app">
 <el-form label-width="200px">
  <el-form-item label="包含小區" required class="housing_input">
  <el-input id="suggestId" v-model="city" placeholder="請輸入小區名稱" name="address_detail" />
  <div id="allmap"/>
  <el-button @click="add_housing">新增</el-button>
  <div v-for="(item,index) in add_housing_list" :key="index" class="housingList">
   <span>{{item}}</span>
   <el-button class="delete_button" @click="delete_housing(index)">刪除</el-button>
  </div>
  </el-form-item>
 </el-form>
 </div>
</template>
 
<script>
export default {
 name: 'demo',
 data(){
 return{
 city: '',
 address_detail: null, //詳細地址
 add_housing_list: ["阿里巴巴"],
 }
 },
 mounted() {
 this.getcity()
 },
 methods:{
 getcity(){
 this.$nextTick(function() {
 var th = this
 // 創建Map實例
 var map = new BMap.Map('allmap')
 // 初始化地圖,設置中心點坐標,
 var point = new BMap.Point(120.211877, 30.255194) // 創建點坐標,漢得公司的經緯度坐標
 map.centerAndZoom(point, 15)
 map.enableScrollWheelZoom()
 
 var ac = new BMap.Autocomplete( // 建立一個自動完成的對象
 {
  'input': 'suggestId',
  'location': map
 })
 var myValue
 ac.addEventListener('onconfirm', function(e) { // 鼠標點擊下拉列表后的事件
 var _value = e.item.value //獲取點擊的條目
 myValue = _value.province + _value.city + _value.district + _value.street + _value.business //地址拼接賦給一個變量
 th.city = myValue //將地址賦給data中的city
 // console.log(th.city)
 setPlace()
 })
 // console.log(ac.pc.input)
 function setPlace() {
 map.clearOverlays() // 清除地圖上所有覆蓋物
 function myFun() {
  th.userlocation = local.getResults().getPoi(0).point // 獲取第一個智能搜索的結果
  map.centerAndZoom(th.userlocation, 18)
  map.addOverlay(new BMap.Marker(th.userlocation)) // 添加標注
 }
 
 var local = new BMap.LocalSearch(map, { // 智能搜索
  onSearchComplete: myFun
 })
 local.search(myValue)
 
 // 測試輸出坐標(指的是輸入框最后確定地點的經緯度)
 map.addEventListener('click', function(e) {
  // 經度
  console.log(th.userlocation.lng)
  // 緯度
  console.log(th.userlocation.lat)
 })
 }
 },)
 },
 // 新增小區 點擊的地址增加進list
 add_housing() {
 this.add_housing_list.push(this.city)
 },
 // 刪除小區
 delete_housing(index) {
 // console.log(index)
 this.add_housing_list.splice(index, 1)
 },
}
}
</script>
 
<style scoped>
.housingList{
 margin-top:20px;
}
.delete_button{
 color: #409EFF;
 text-decoration: underline;
 border:none;
 background:#fff;
 cursor: pointer;
 margin-left:20px;
}
 
.el-input{
 width: 800px;
 }
 .housing_input .el-input{
 width: 730px;
 }
 
 #allmap{
 width: 400px;
 height: 400px;
 font-family: "微軟雅黑";
 display: none;
}
 
</style>

看完上述內容,你們掌握怎么在vue中使用BMap百度地圖實現一個即時搜索功能的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!

新聞標題:怎么在vue中使用BMap百度地圖實現一個即時搜索功能-創新互聯
URL標題:http://newbst.com/article40/dooeho.html

成都網站建設公司_創新互聯,為您提供建站公司云服務器做網站用戶體驗服務器托管全網營銷推廣

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

小程序開發