vue+elementUi實(shí)現(xiàn)點(diǎn)擊地圖自動(dòng)填充經(jīng)緯度以及地點(diǎn)
本文實(shí)例為大家分享了vue+elementUi實(shí)現(xiàn)點(diǎn)擊地圖自動(dòng)填充經(jīng)緯度以及地點(diǎn)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)代碼
1.安裝組件
終端運(yùn)行:
npm install vue-baidu-map --save
2.HTML代碼塊
<el-form-item label="經(jīng)度" :label-width="formLabelWidth" prop="longitude"> ?? ?<el-input ?class="lineinput" placeholder="點(diǎn)擊地圖輸入經(jīng)度" ?style="width: 80%;" size="samll" v-model.number="form.longitude"></el-input> </el-form-item> <el-form-item label="維度" :label-width="formLabelWidth" prop="latitude"> ? ? <el-input ?class="lineinput" placeholder="點(diǎn)擊地圖輸入維度" style="width: 80%;" size="samll" v-model.number="form.latitude"></el-input> </el-form-item> <el-form-item label="廠區(qū)地址" :label-width="formLabelWidth" prop="location"> ? ? <el-input ?class="lineinput" placeholder="點(diǎn)擊地圖輸入廠區(qū)地址" style="width: 80%;" size="small" v-model="form.location"></el-input> </el-form-item> <el-form-item :label-width="formLabelWidth"> ? ? <baidu-map ?class="map" :center="center" :zoom="zoom" @ready="handler" ? ? :scroll-wheel-zoom="true" ? ? @click="clickEvent" ? ? ak="33B192o1jPaqOHASGGAIkoMuwi8W76j3"> ? ? ?? ?<!-- 地圖控件位置 --> ? ? ? ? <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation> ? ? ? ? <!-- 獲取城市列表 --> ? ? ? ? <bm-city-list anchor="BMAP_ANCHOR_TOP_LEFT"></bm-city-list> ? ? ? ? <!-- 定位當(dāng)前位置 --> ? ? ? ? <bm-geolocation anchor="BMAP_ANCHOR_BOTTOM_RIGHT" ?:showAddressBar="true" :autoLocation="true" @locationSuccess="getLoctionSuccess" ></bm-geolocation> ? ? ? ? <!-- 地圖容器 --> ? ? ? ? <bm-view :style="{width:'75%',height: '500px'}"></bm-view> ? ? ?</baidu-map> </el-form-item>
3.導(dǎo)入依賴
import {BaiduMap,BmNavigation,BmView,BmGeolocation,BmCityList} from 'vue-baidu-map'
4.js代碼塊
export default { ? name: "mapDialog", ?? ?components: { ? ? ? ? ? ? BaiduMap, ? ? ? ? ? ? BmNavigation, ? ? ? ? ? ? BmView, ? ? ? ? ? ? BmGeolocation, ? ? ? ? ? ? BmCityList, ? ? ? ? ? ? ElImageViewer ? ? ? ? }, ?? ?data() { ? ? ? ? return { ??? ??? ??? ?center: {lng: 121.833138, lat: 39.081725}, ? ? ? ? ? ? ? ? zoom: 12, ? ? ? ? ? ? ? ? mapVisible:false, ? ? ? ? ? ? ? ? form:{ ? ? ? ? ? ? ? ? ? ? longitude:'', ? ? ? ? ? ? ? ? ? ? latitude:'', ? ? ? ? ? ? ? ? ? ? location:'', ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? clientHeight:document.documentElement.clientHeight-90, // 設(shè)置屏幕高度 ? ? ? ? ? ? ? ? iconUrl:'static/zuobiao.gif',//點(diǎn)擊坐標(biāo)標(biāo)記 ? ? ? ? } ??? ?} ?? ?methods:{ ? ? ? ? handler ({BMap, map}) { ? ? ? ? ? let _this = this;?? ?// 設(shè)置一個(gè)臨時(shí)變量指向vue實(shí)例; ? ? ? ? ? var geolocation = new BMap.Geolocation(); ? ? ? ? ? geolocation.getCurrentPosition(function(r){ ? ? ? ? ? ? console.log(r); ? ? ? ? ? ? _this.center = {lng: r.longitude, lat: r.latitude};?? ??? ?// 設(shè)置center屬性值 ? ? ? ? ? ? _this.autoLocationPoint = {lng: r.longitude, lat: r.latitude};?? ??? ?// 自定義覆蓋物 ? ? ? ? ? ? _this.initLocation = true; ? ? ? ? ? },{enableHighAccuracy: true}) ? ? ? ? ? ? window.map = map; ? ? ? ? }, ? ? ? ? //點(diǎn)擊地圖監(jiān)聽 ? ? ? ? clickEvent(e){ ? ? ? ? ? map.clearOverlays(); ? ? ? ? ? let Icon_0 = new BMap.Icon("static/zuobiao.gif", new BMap.Size(64, 64), {anchor: new BMap.Size(18, 32),imageSize: new BMap.Size(36, 36)}); ? ? ? ? ? var myMarker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat),{icon: Icon_0}); ? ? ? ? ? map.addOverlay(myMarker); ? ? ? ? ? //用所定位的經(jīng)緯度查找所在地省市街道等信息 ? ? ? ? ? var point = new BMap.Point(e.point.lng, e.point.lat); ? ? ? ? ? var gc = new BMap.Geocoder(); ? ? ? ? ? let _this = this; ? ? ? ? ? gc.getLocation(point, function (rs) { ? ? ? ? ? ? var addComp = rs.addressComponents; ? ? ? ? ? ? //console.log(rs.address);//地址信息 ? ? ? ? ? ? _this.form.location = rs.address; ? ? ? ? ? }); ? ? ? ? ? ? this.form.longitude = e.point.lng; ? ? ? ? ? ? this.form.latitude = e.point.lat; ? ? ? ? }, ? ? ? ? //定位成功回調(diào) ? ? ? ? getLoctionSuccess(point, AddressComponent, marker){ ? ? ? ? ? map.clearOverlays(); ? ? ? ? ? let Icon_0 = new BMap.Icon("static/zuobiao.gif", new BMap.Size(64, 64), {anchor: new BMap.Size(18, 32),imageSize: new BMap.Size(36, 36)}); ? ? ? ? ? var myMarker = new BMap.Marker(new BMap.Point(point.point.lng, point.point.lat),{icon: Icon_0}); ? ? ? ? ? map.addOverlay(myMarker); ? ? ? ? ? this.form.longitude = point.point.lng; ? ? ? ? ? this.form.latitude = point.point.lat; ? ? ? ? }, ? ? ? ? findlocation(){ ? ? ? ? ? this.$emit("findlocdata",this.form) ? ? ? ? ? this.mapVisible = false ? ? ? ? }, ? ? ? ? mapShow(){ ? ? ? ? ? this.mapVisible = true ? ? ? ? }, ? ?}
結(jié)果展示
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js中Line第三方登錄api的實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue.js中Line第三方登錄api實(shí)現(xiàn)代碼,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06Vue+Express實(shí)現(xiàn)登錄注銷功能的實(shí)例代碼
這篇文章主要介紹了Vue+Express實(shí)現(xiàn)登錄,注銷功能,本文通過實(shí)例代碼講解的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05vue3+ts+element-plus實(shí)際開發(fā)之統(tǒng)一調(diào)用彈窗封裝的詳細(xì)過程
這篇文章主要介紹了vue3+ts+element-plus實(shí)際開發(fā)之統(tǒng)一調(diào)用彈窗封裝的詳細(xì)過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03vue-cli如何修改打包項(xiàng)目結(jié)構(gòu)及前綴
這篇文章主要介紹了vue-cli如何修改打包項(xiàng)目結(jié)構(gòu)及前綴問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07vue中watch和computed的區(qū)別與使用方法
這篇文章主要給大家介紹了關(guān)于vue中watch和computed的區(qū)別與使用方法的相關(guān)資料,文中通過實(shí)例代碼結(jié)束的非常詳細(xì),對大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08