前端web用腾讯地图api根据地址获取经纬度
生活随笔
收集整理的這篇文章主要介紹了
前端web用腾讯地图api根据地址获取经纬度
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
需求:使用騰訊地圖,通過輸入的地址獲取經(jīng)緯度
1.先引入騰訊地圖,參考https://blog.csdn.net/l13620804253/article/details/117254651
2.要調(diào)用騰訊地圖API獲取當(dāng)前位置的經(jīng)緯度,需要使用騰訊地圖位置服務(wù)https://apis.map.qq.com/ws/geocoder/v1/接口(附上樓梯https://lbs.qq.com/service/webService/webServiceGuide/webServiceGeocoder),該接口前端直接正常請求會跨越,需要jsonp來避免報錯;
3.引入jsonp:
1)安裝vue-jsonp:
2)在main.js中導(dǎo)入:
import { VueJsonp } from 'vue-jsonp' Vue.use(VueJsonp)4.定義方法:
// 根據(jù)地址獲取坐標(biāo)addrToGetCoordinate(addr) {this.$jsonp('https://apis.map.qq.com/ws/geocoder/v1/', {key: 'ZBABZ-S5LKO-AQAWR-SNHUD-V3AQS-MSBMB',output: 'jsonp',address: addr}).then((res) => {console.log(res)if (res.status === 0) {// 處理得到的經(jīng)緯度this.coordinate.lat = res.result.location.lat.toFixed(6)this.coordinate.lng = res.result.location.lng.toFixed(6)this.postForm.store_longitude = res.result.location.lngthis.postForm.store_latitude = res.result.location.lat// 用獲取到的經(jīng)緯度,修改地圖的中心點(diǎn)this.changeCenter(res.result.location.lat.toFixed(6), res.result.location.lng.toFixed(6))}}).catch((e) => {console.log(e)})},5.然后在對應(yīng)的地方使用;
以上就是web端騰訊地圖,通過地址獲取經(jīng)緯度的方法,記得關(guān)注點(diǎn)贊~~摸摸噠
總結(jié)
以上是生活随笔為你收集整理的前端web用腾讯地图api根据地址获取经纬度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 塔里木大学有没有计算机专业,塔里木大学最
- 下一篇: 苹果手机html5摇一摇游戏戏码,利用H