詳解vue實(shí)現(xiàn)坐標(biāo)拾取器功能示例
需求
1、搜索具體地址,自動(dòng)填寫經(jīng)緯度,并在地圖上標(biāo)記
2、點(diǎn)擊地圖上一點(diǎn),可重新填寫經(jīng)緯度并且標(biāo)記
代碼
在dom新建div渲染地圖
<el-form-item label="店鋪地址" prop="address"> <el-input v-model="fristForm.address"></el-input> <el-input class="long-lat" v-model="fristForm.longitude" placeholder="經(jīng)度" ></el-input> <el-input class="long-lat" v-model="fristForm.latitude" placeholder="緯度" ></el-input> <el-button size="mini" type="primary" @click="searchKeyword" >搜索</el-button > </el-form-item> <span class="changeAddress">點(diǎn)擊地圖更換分店定位地址</span> <!-- 渲染地圖的div容器 --> <div id="container" class="mapbox"></div>
js定義地圖變量并設(shè)置需求
var searchService,geocoder,map,markersArray = []; <script> export default { mounted() { this.init(); }, methods:{ init() { var that = this; var center = new qq.maps.LatLng(39.916527, 116.397128); var map = new qq.maps.Map(document.getElementById("container"), { center: center, zoom: 13 }); var latlngBounds = new qq.maps.LatLngBounds(); qq.maps.event.addListener(map, "click", function(event) { console.log(event); that.fristForm.longitude = event.latLng.getLng(); // 經(jīng)度 that.fristForm.latitude = event.latLng.getLat(); // 緯度 if (markersArray) { for (let i in markersArray) { markersArray[i].setMap(null); } } var marker = new qq.maps.Marker({ map: map, position: event.latLng }); markersArray.push(marker); }); geocoder = new qq.maps.Geocoder({ complete: function(result) { console.log(result); that.fristForm.longitude = result.detail.location.lng; that.fristForm.latitude = result.detail.location.lat; map.setCenter(result.detail.location); var marker = new qq.maps.Marker({ map: map, position: result.detail.location }); markersArray.push(marker); } }); }, }, // 搜索地址 searchKeyword() { var keyword = this.fristForm.address; this.clearOverlays(markersArray); //根據(jù)輸入的城市設(shè)置搜索范圍 // searchService.setLocation("北京"); //根據(jù)輸入的關(guān)鍵字在搜索范圍內(nèi)檢索 if (keyword) { // searchService.search(keyword); geocoder.getLocation(keyword); } else { alert("請(qǐng)輸入地址"); } }, } </script>
文檔參考
以上代碼使用的是jsapi功能,目前對(duì)應(yīng)功能已升級(jí)JavaScript API GL,地址解析功能可直接調(diào)取接口使用,歡迎大家體驗(yàn)!
地址解析(地址轉(zhuǎn)坐標(biāo))
JavaScript API GL參考手冊(cè)
到此這篇關(guān)于詳解vue實(shí)現(xiàn)坐標(biāo)拾取器功能示例的文章就介紹到這了,更多相關(guān)vue 坐標(biāo)拾取器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue使用axios導(dǎo)出后臺(tái)返回的文件流為excel表格詳解
這篇文章主要介紹了vue使用axios導(dǎo)出后臺(tái)返回的文件流為excel表格方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08vue+element-ui+ajax實(shí)現(xiàn)一個(gè)表格的實(shí)例
下面小編就為大家分享一篇vue+element-ui+ajax實(shí)現(xiàn)一個(gè)表格的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03vue與bootstrap實(shí)現(xiàn)時(shí)間選擇器的示例代碼
本篇文章主要介紹了vue與bootstrap實(shí)現(xiàn)時(shí)間選擇器的示例代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-08-08Vue項(xiàng)目如何部署到SpringBoot工程下
這篇文章主要介紹了Vue項(xiàng)目如何部署到SpringBoot工程下問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07Springboot運(yùn)用vue+echarts前后端交互實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)圖
我們做項(xiàng)目的時(shí)候,常常需要一些統(tǒng)計(jì)圖來展示我們的數(shù)據(jù),作為web開發(fā)人員,會(huì)實(shí)現(xiàn)統(tǒng)計(jì)圖是我們必會(huì)的技能。我將帶大家來實(shí)現(xiàn)動(dòng)態(tài)餅圖的實(shí)現(xiàn),感興趣的可以了解一下2021-06-06vue3實(shí)現(xiàn)H5表單驗(yàn)證組件的示例
本文主要介紹了vue3實(shí)現(xiàn)H5表單驗(yàn)證組件的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04解決vue v-for 遍歷循環(huán)時(shí)key值報(bào)錯(cuò)的問題
今天小編就為大家分享一篇解決vue v-for 遍歷循環(huán)時(shí)key值報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09