最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue利用vue-baidu-map實(shí)現(xiàn)獲取經(jīng)緯度和搜索地址

 更新時(shí)間:2022年09月22日 15:03:14   作者:格斗家不愛(ài)在外太空沉思  
在開(kāi)發(fā)項(xiàng)目的時(shí)候,發(fā)現(xiàn)需要獲取經(jīng)緯度,由于這個(gè)項(xiàng)目是用vue寫(xiě)的,最后決定使用vue-baidu-map來(lái)快速獲取經(jīng)緯度,感興趣的可以了解一下

在開(kāi)發(fā)項(xiàng)目的時(shí)候,發(fā)現(xiàn)需要獲取經(jīng)緯度,由于這個(gè)項(xiàng)目是用vue寫(xiě)的,最后決定使用vue-baidu-map來(lái)快速獲取經(jīng)緯度

基于 Vue.js 封裝的百度地圖組件,運(yùn)行流暢,代碼簡(jiǎn)單易懂,幾乎包含了百度地圖官方的所有API,文檔地址:https://dafrok.github.io/vue-baidu-map/#/zh/start/installation

1.申請(qǐng)百度地圖密鑰

搜索'百度地圖開(kāi)放平臺(tái)',選擇頭部導(dǎo)航欄開(kāi)發(fā)文檔里的JavaScript API

然后點(diǎn)擊申請(qǐng)密鑰

2.安裝vue-baidu-map

終端運(yùn)行

npm install vue-baidu-map --save

main.js里全局注冊(cè)

import Vue from 'vue'
import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {
  // ak 是在百度地圖開(kāi)發(fā)者平臺(tái)申請(qǐng)的密鑰 詳見(jiàn) http://lbsyun.baidu.com/apiconsole/key */
  ak: 'YOUR_APP_KEY'
})

引入組件,初始化地圖,開(kāi)啟鼠標(biāo)滾輪控制地圖縮放

<template>
  <baidu-map id="allmap" @ready="mapReady" :scroll-wheel-zoom="true">
  </baidu-map>
</template>

<script>
export default {
    methods: {
        //地圖初始化
        mapReady({ BMap, map }) {
          this.point = new BMap.Point(113.27, 23.13); // 選擇一個(gè)經(jīng)緯度作為中心點(diǎn)
          map.centerAndZoom(this.point, 12); //設(shè)置地圖中心點(diǎn)和縮放級(jí)別
          this.BMap=BMap
          this.map=map
        }
    }
}
</script>

<style>
#allmap{
  height: 450px;
  width: 100%;
  margin: 10px 0;
}
</style>

一個(gè)簡(jiǎn)單的地圖就出來(lái)了

3.獲取經(jīng)緯度

3.1 為地圖添加點(diǎn)擊事件,獲取經(jīng)緯度

<template>
  <baidu-map id="allmap" @ready="mapReady" @click="getLocation" :scroll-wheel-zoom="true">
  </baidu-map>
</template>

<script>
export default {
    data () {
        return {
          infoWindowShow:false,
          longitude:'',
          latitude:'',
        }
      },
    methods: {
        getLocation(e){
          this.longitude=e.point.lng
          this.latitude=e.point.lat
          this.infoWindowShow=true
        },
    }
}
</script>

3.2 添加BmInfoWindow信息窗口組件和BmMarker標(biāo)注,點(diǎn)擊地圖時(shí)彈出

<template>
  <baidu-map id="allmap" @ready="mapReady" @click="getLocation" :scroll-wheel-zoom="true">
      <bm-marker v-if="infoWindowShow" :position="{lng: longitude, lat: latitude}">
          <bm-label content="" :labelStyle="{color: 'red', fontSize : '24px'}" :offset="{width: -35, height: 30}"/>
      </bm-marker>
      <bm-info-window :position="{lng: longitude, lat: latitude}" :show="infoWindowShow" @clickclose="infoWindowClose">
          <p>緯度:{{this.latitude}}</p>
          <p>經(jīng)度:{{this.longitude}}</p>
      </bm-info-window>
  </baidu-map>
</template>

3.3 添加BmAutoComplete組件,輸入地址自動(dòng)補(bǔ)全

<template>
  <baidu-map id="allmap" @ready="mapReady" @click="getLocation" :scroll-wheel-zoom="true">
      <div style="display:flex;justify-content:center;margin:15px">
          <bm-auto-complete v-model="searchJingwei" :sugStyle="{zIndex: 999999}">
            <el-input v-model="searchJingwei" style="width:300px;margin-right:15px" placeholder="輸入地址"></el-input>
          </bm-auto-complete>
          <el-button type="primary" @click="getBaiduMapPoint">搜索</el-button>
      </div>
      <bm-marker v-if="infoWindowShow" :position="{lng: longitude, lat: latitude}">
          <bm-label content="" :labelStyle="{color: 'red', fontSize : '24px'}" :offset="{width: -35, height: 30}"/>
      </bm-marker>
      <bm-info-window :position="{lng: longitude, lat: latitude}" :show="infoWindowShow" @clickclose="infoWindowClose">
          <p>緯度:{{this.latitude}}</p>
          <p>經(jīng)度:{{this.longitude}}</p>
      </bm-info-window>
  </baidu-map>
</template>

3.4 最后點(diǎn)擊搜索按鈕地圖跳轉(zhuǎn)到搜索位置并打開(kāi)信息窗口和標(biāo)注

<script>
export default {
    data () {
        return {
          infoWindowShow:false,
          longitude:'',
          latitude:'',
        }
      },
    methods: {
        getBaiduMapPoint(){
          let that=this
          let myGeo = new this.BMap.Geocoder()
          //逆地址解析
          myGeo.getPoint(this.searchJingwei,function(point){
            if(point){
              that.map.centerAndZoom(point,15)
              that.latitude=point.lat
              that.longitude=point.lng
              that.infoWindowShow=true
            }
          })
        },
    }
}
</script>

最后放上全部代碼

<template>
  <div>
      <baidu-map
        style="display:flex;flex-direction: column-reverse;" 
        id="allmap"
        @ready="mapReady"
        @click="getLocation"
        :scroll-wheel-zoom="true"
      >
        <div style="display:flex;justify-content:center;margin:15px">
          <bm-auto-complete v-model="searchJingwei" :sugStyle="{zIndex: 999999}">
            <el-input v-model="searchJingwei" style="width:300px;margin-right:15px" placeholder="輸入地址"></el-input>
          </bm-auto-complete>
          <el-button type="primary" @click="getBaiduMapPoint">搜索</el-button>
        </div>
        <bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_LEFT"></bm-map-type>
        <bm-marker v-if="infoWindowShow" :position="{lng: longitude, lat: latitude}">
          <bm-label content="" :labelStyle="{color: 'red', fontSize : '24px'}" :offset="{width: -35, height: 30}"/>
        </bm-marker>
        <bm-info-window :position="{lng: longitude, lat: latitude}" :show="infoWindowShow" @clickclose="infoWindowClose">
          <p>緯度:{{this.latitude}}</p>
          <p>經(jīng)度:{{this.longitude}}</p>
        </bm-info-window>
      </baidu-map>
  </div>
</template>

<script>
export default {
  data () {
    return {
      searchJingwei:'',
      infoWindowShow:false,
      longitude:'',
      latitude:'',
      point:''
    }
  },
  methods: {
    //地圖初始化
    mapReady({ BMap, map }) {
      // 選擇一個(gè)經(jīng)緯度作為中心點(diǎn)
      this.point = new BMap.Point(113.27, 23.13);
      map.centerAndZoom(this.point, 12);
      this.BMap=BMap
      this.map=map
    },
    //點(diǎn)擊獲取經(jīng)緯度
    getLocation(e){
      this.longitude=e.point.lng
      this.latitude=e.point.lat
      this.infoWindowShow=true
    },
    getBaiduMapPoint(){
      let that=this
      let myGeo = new this.BMap.Geocoder()
      myGeo.getPoint(this.searchJingwei,function(point){
        if(point){
          that.map.centerAndZoom(point,15)
          that.latitude=point.lat
          that.longitude=point.lng
          that.infoWindowShow=true
        }

      })
    },
    //信息窗口關(guān)閉
    infoWindowClose(){
      this.latitude=''
      this.longitude=''
      this.infoWindowShow=false
    },
  },
}
</script>

<style lang="scss" scoped>
#allmap{
  height: 450px;
  width: 100%;
  margin: 10px 0;
}
</style>

最終實(shí)現(xiàn)效果

到此這篇關(guān)于Vue利用vue-baidu-map實(shí)現(xiàn)獲取經(jīng)緯度和搜索地址的文章就介紹到這了,更多相關(guān)Vue vue-baidu-map經(jīng)緯度內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue路由跳轉(zhuǎn)時(shí)判斷用戶(hù)是否登錄功能的實(shí)現(xiàn)

    vue路由跳轉(zhuǎn)時(shí)判斷用戶(hù)是否登錄功能的實(shí)現(xiàn)

    下面小編就為大家?guī)?lái)一篇vue路由跳轉(zhuǎn)時(shí)判斷用戶(hù)是否登錄功能的實(shí)現(xiàn)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • vuejs選中當(dāng)前樣式active的實(shí)例

    vuejs選中當(dāng)前樣式active的實(shí)例

    今天小編就為大家分享一篇vuejs選中當(dāng)前樣式active的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • vue3?使用provide?inject父子組件傳值失敗且子組件不響應(yīng)

    vue3?使用provide?inject父子組件傳值失敗且子組件不響應(yīng)

    這篇文章主要介紹了vue3使用provide?inject父子組件傳值傳不過(guò)去且傳遞后子組件不具備響應(yīng)性問(wèn)題解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • vue3常用響應(yīng)式對(duì)象的api,你全用過(guò)了嗎

    vue3常用響應(yīng)式對(duì)象的api,你全用過(guò)了嗎

    這篇文章主要給大家介紹了關(guān)于vue3常用響應(yīng)式對(duì)象api的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue3具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-02-02
  • Vue+Element UI+Lumen實(shí)現(xiàn)通用表格分頁(yè)功能

    Vue+Element UI+Lumen實(shí)現(xiàn)通用表格分頁(yè)功能

    這篇文章主要介紹了Vue+Element UI+Lumen實(shí)現(xiàn)通用表格分頁(yè)功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • vue如何修改data中的obj數(shù)據(jù)的屬性

    vue如何修改data中的obj數(shù)據(jù)的屬性

    這篇文章主要介紹了vue如何修改data中的obj數(shù)據(jù)的屬性,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)詳解

    Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)詳解

    element-plus根據(jù)官網(wǎng)文檔,推薦用戶(hù)采用按需導(dǎo)入的方式進(jìn)行導(dǎo)入,下面這篇文章主要給大家介紹了關(guān)于Vue3+Element?Plus按需引入(自動(dòng)導(dǎo)入)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • vuejs如何清空表單數(shù)據(jù)、刪除對(duì)象中的空屬性公共方法

    vuejs如何清空表單數(shù)據(jù)、刪除對(duì)象中的空屬性公共方法

    這篇文章主要介紹了vuejs如何清空表單數(shù)據(jù)、刪除對(duì)象中的空屬性公共方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • 解決vue中this.$set()不更新問(wèn)題

    解決vue中this.$set()不更新問(wèn)題

    我在做一個(gè)附件刪除功能的時(shí)候發(fā)現(xiàn),明明打印出來(lái)附件已經(jīng)沒(méi)有數(shù)據(jù)了但是頁(yè)面就是不刷新, this.$set()不生效,所以本文小編給大家介紹了vue中this.$set()不更新的解決方法,需要的朋友可以參考下
    2023-11-11
  • Vue項(xiàng)目路由刷新的實(shí)現(xiàn)代碼

    Vue項(xiàng)目路由刷新的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Vue項(xiàng)目路由刷新的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-04-04

最新評(píng)論

平南县| 绩溪县| 兖州市| 兰坪| 隆尧县| 沁源县| 武城县| 从化市| 延长县| 娱乐| 博白县| 丰宁| 玛曲县| 淮安市| 烟台市| 崇仁县| 浦城县| 南城县| 靖边县| 宣威市| 邯郸市| 抚顺市| 孟津县| 枣阳市| 潍坊市| 栖霞市| 招远市| 梅州市| 邹平县| 东光县| 清丰县| 微山县| 西安市| 彭泽县| 宜川县| 清水县| 德安县| 罗田县| 南丹县| 正安县| 新郑市|