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

vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的示例代碼

 更新時間:2024年08月08日 16:48:52   作者:kurcp  
這篇文章主要介紹了vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的示例代碼,需要的朋友可以參考下

html 

  <el-tag v-if='isSave' size="small" style="cursor:pointer;margin-left:20px;" @click="open()">點擊選取</el-tag>
<el-dialog
          class="dialog companygoodsLog"
          v-model="visible"
          :close-on-click-modal="false"
          :draggable="true"
          :show-close="false"
          title="位置選擇"
          destroy-on-close
          style="border-radius: 4px;background-color: #ffffff"
          top="100px"
          width="80%">
          <div style="height:40px;width:100%;display: flex;align-items: center;">
              <el-select
                  v-model="areaValue"
                  filterable
                  style='width:350px'
                  remote
                  reserve-keyword
                  placeholder="請輸入關(guān)鍵詞"
                  :remote-method="remoteMethod"
                  :loading="loading"
                  @change="currentSelect"
              >
                      <el-option
                        v-for="item in areaList"
                        :key="item.id"
                        :label="item.name"
                        :value="item"
                        class="one-text"
                    >
                      <span style="float: left">{{ item.name }}</span>
                      <span style="float: right; color: #8492a6; font-size: 13px">{{item.district}}{{item.address}}</span>
                  </el-option>
              </el-select>
          </div>
          <div id="container" style="height:500px;width:100%;margin-top:10px;"></div>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="visible = false"><span style="color: #5E5E5E">關(guān)閉</span></el-button>
              <el-button color="#68964C" @click="confirmData">
              確定
              </el-button>
            </span>
          </template>
      </el-dialog>

 ts:

<script setup lang="ts">
import { reactive,ref,onMounted, onUnmounted,watch  } from 'vue'
import AMapLoader from "@amap/amap-jsapi-loader";
const dialogMap = ref(false)
const mapContainer = ref(null);
const visible:any = ref(false)
const areaList:any =ref([])
const areaValue = ref('')
let map:any = null
const loading:any = ref(false)
const checkedForm:any = ref()
let AutoComplete:any = null
let aMap:any = null
let geoCoder:any = null
const initMap = () => {
    AMapLoader.load({
    key: "高德key",
    version: "2.0", 
    plugins: ["AMap.Geocoder", "AMap.AutoComplete"], 
  }).then((AMap:any) => {
      aMap = AMap
      map = new AMap.Map("container", {
        // 設(shè)置地圖容器id
        viewMode: "3D", // 是否為3D地圖模式
        zoom: 11, // 初始化地圖級別
        center: [116.397428, 39.90923], // 初始化地圖中心點位置
      });
      AutoComplete = new AMap.AutoComplete({
        city:'全國',
      });
      geoCoder = new AMap.Geocoder({
        city: "010", //城市設(shè)為北京,默認(rèn):“全國”
        radius: 1000, //范圍,默認(rèn):500
      });
      map.on('click',(e:any)=>{
        addmark(e.lnglat.getLng(),e.lnglat.getLat(),AMap)
      })
    })
    .catch((e) => {
      console.log(e);
    });
}
let marker:any = null
const addmark = (lat:any,lng:any,AMap:any) => {
    marker && removeMarker()
    marker = new AMap.Marker({
            position: new AMap.LngLat(lat, lng),
            title: '北京',
            zoom: 13
    });
    checkedForm.value = {
        lat:lng,
        lng:lat,
    }
    map.add(marker);
    map.setCenter([lat, lng],'',500);
}
const removeMarker = () => {
    map.remove(marker)
}
const remoteMethod = (searchValue:any) => {
    if (searchValue !== "") {
      setTimeout(() => {
          AutoComplete.search(searchValue, (status:any, result:any) => {
              console.log(result,status)
              if(result.tips?.length){
                  areaList.value = result?.tips
              }
          });
      }, 200);
    } else {
    }
}
const currentSelect = (val:any) => {
    checkedForm.value = {
        lat:val.location?.lat,
        lng:val.location?.lng,
    }
    console.log(val)
    areaValue.value = val.name
    addmark(val.location?.lng,val.location?.lat,aMap)
    map.setCenter([val.location?.lng,val.location?.lat],'',500);
}
const confirmData = () => {
    if(!checkedForm.value?.lat || !checkedForm.value?.lng){
        return ElMessage.error('請選擇地址')
    }else{
      console.log(checkedForm.value)
      visible.value = false
      areaValue.value = ''
      map?.destroy();
      list.longitude = checkedForm.value.lng
      list.latitude = checkedForm.value.lat
    }
}
const open = () => {
    initMap()
    visible.value = true
}
defineExpose({
    open
})
onUnmounted(() => {
  map?.destroy();
});
</script>

根據(jù)經(jīng)緯度展示地圖標(biāo)點 

<el-button v-if="list.longitude" type="primary"  style="margin-bottom: 20px;"@click="showMapDialog()">點擊查看位置</el-button>
<el-dialog v-model="dialogMap" title="位置信息" width="900px">
            <div ref="mapContainer" id="container" style="height:500px;width:100%;margin-top:10px;"></div>
        </el-dialog>
<script setup>
import { reactive, ref, onMounted, toRefs, watch } from 'vue'
import AMapLoader from "@amap/amap-jsapi-loader";
const dialogVisible = ref(false)
const dialogMap = ref(false)
const mapContainer = ref(null);
const props = defineProps({
    isShow15: {
        type: Boolean,
        default: false,
    },
    list:{
        default:{}
    }
});
const emits = defineEmits(['close15'])
const closeDialog = () => {
    emits('close15', false)
}
const mapList = ref([])
watch(() => props.isShow15, (val) => {
    // console.log(val)
    dialogVisible.value = val
}, { immediate: true })
watch(() => props.list, (val) => {
    mapList.value = val
}, { immediate: true })
const showMapDialog = async () => {
    dialogMap.value = true;
    initMap();
};
let map = null
let aMap = null
let AutoComplete = null
let geoCoder = null
let marker = null;
const initMap = () => {
    AMapLoader.load({
    key: "高德地圖key",
    version: "2.0", 
    plugins: ["AMap.Geocoder", "AMap.AutoComplete"], 
  }).then((AMap) => {
      aMap = AMap
      map = new AMap.Map("container", {
        // 設(shè)置地圖容器id
        viewMode: "2D", // 是否為3D地圖模式
        zoom: 21, // 初始化地圖級別
        center: [parseFloat(mapList.value.longitude), parseFloat(mapList.value.latitude)], // 初始化地圖中心點位置
      });
      AutoComplete = new AMap.AutoComplete({
        city:'全國',
      });
      geoCoder = new AMap.Geocoder({
        city: "010", //城市設(shè)為北京,默認(rèn):“全國”
        radius: 1000, //范圍,默認(rèn):500
      });
      geoCoder = new AMap.Geocoder({
        city: "全國", //城市設(shè)為北京,默認(rèn):“全國”
        radius: 1000, //范圍,默認(rèn):500
      })
      marker = new aMap.Marker({
            position: [parseFloat(mapList.value.longitude), parseFloat(mapList.value.latitude)],
            map: map,
        });
    })
    .catch((e) => {
      console.log(e);
    });
}
</script>

到此這篇關(guān)于vue3 高德地圖關(guān)鍵詞搜索獲取經(jīng)緯度的文章就介紹到這了,更多相關(guān)vue3 高德地圖獲取經(jīng)緯度內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue2.0自定義指令示例代碼詳解

    vue2.0自定義指令示例代碼詳解

    指令通常以"v-"作為前綴, 以方便Vue知道你在使用一種特殊的標(biāo)記。這篇文章主要介紹了vue2.0自定義指令的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • vue實現(xiàn)簡單跑馬燈效果

    vue實現(xiàn)簡單跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)簡單跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Vue動態(tài)組件component的深度使用說明

    Vue動態(tài)組件component的深度使用說明

    這篇文章主要介紹了Vue動態(tài)組件component的深度使用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue對IFrame內(nèi)嵌web頁面的緩存實現(xiàn)過程

    vue對IFrame內(nèi)嵌web頁面的緩存實現(xiàn)過程

    這篇文章主要介紹了vue對IFrame內(nèi)嵌web頁面的緩存實現(xiàn)過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • Vue中的Computed實現(xiàn)原理分析

    Vue中的Computed實現(xiàn)原理分析

    這篇文章主要介紹了Vue中的Computed實現(xiàn)原理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • vue項目配置vuex并開啟熱更新方式

    vue項目配置vuex并開啟熱更新方式

    這篇文章主要介紹了vue項目配置vuex并開啟熱更新方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 在vscode里使用.vue代碼模板的方法

    在vscode里使用.vue代碼模板的方法

    本篇文章主要介紹了在vscode里使用.vue代碼模板的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • 常見的5種Vue組件通信方式總結(jié)

    常見的5種Vue組件通信方式總結(jié)

    在?Vue.js?中,組件通信是開發(fā)過程中非常重要的一部分,它涉及到不同組件之間的數(shù)據(jù)傳遞和交互,本文將介紹如何實現(xiàn)父子組件之間的有效通信,并盤點了常見的5種Vue組件通信方式總結(jié),需要的朋友可以參考下
    2024-03-03
  • vue使用swiper實現(xiàn)中間大兩邊小的輪播圖效果

    vue使用swiper實現(xiàn)中間大兩邊小的輪播圖效果

    這篇文章主要介紹了vue使用swiper實現(xiàn)中間大兩邊小的輪播圖效果,本文分步驟通過實例代碼講解的非常詳細(xì),需要的朋友可以參考下
    2019-11-11
  • Vue實現(xiàn)Chrome小恐龍游戲的示例代碼

    Vue實現(xiàn)Chrome小恐龍游戲的示例代碼

    Google 給 Chrome 瀏覽器加了一個有趣的彩蛋,本文就詳細(xì)的介紹一下Vue實現(xiàn)Chrome小恐龍游戲的示例代碼,具有一定的參考價值,感興趣的可以了解一下
    2022-04-04

最新評論

襄垣县| 临泉县| 蓬安县| 枞阳县| 武平县| 东乌珠穆沁旗| 宁陕县| 六枝特区| 黄陵县| 平安县| 新竹市| 泾源县| 大理市| 鄂尔多斯市| 浦江县| 葵青区| 龙里县| 象州县| 黎川县| 广丰县| 麻江县| 林芝县| 山西省| 车险| 岐山县| 沐川县| 安塞县| 昭通市| 濉溪县| 邻水| 九龙城区| 大悟县| 翼城县| 靖西县| 和龙市| 佛教| 韩城市| 建水县| 商城县| 平果县| 和静县|