1、在終端執(zhí)行
npm i --save vue-jsonp
2.在main.js引入?
import {VueJsonp} from 'vue-jsonp'
Vue.use(VueJsonp)
或則直接在需要頁(yè)面引入
import { jsonp } from 'vue-jsonp'
3、寫方法文章來源:http://www.zghlxwxcb.cn/news/detail-709284.html
getUserLocation(address) {
let url = 'https://apis.map.qq.com/ws/geocoder/v1/?address=';
this.$jsonp(url, {
key: '騰訊地圖key',
address: address,
output: 'jsonp'
})
.then(res => {
console.log(res)
console.log(res)
const latitude = res.result.location.lat;
const longitude = res.result.location.lng;
console.log("res.result.location.lat: ",res.result.location.lat);
console.log("res.result.location.lng: ",res.result.location.lng);
this.$wx.openLocation({
latitude: latitude,
longitude: longitude,
name: this.address, // 位置名
address: this.address, // 地址詳情說明
scale: 15, // 地圖縮放級(jí)別,整型值,范圍從1~28。默認(rèn)為最大
infoUrl: '' ,// 在查看位置界面底部顯示的超鏈接,可點(diǎn)擊跳轉(zhuǎn)
});
})
.catch(err => {
console.log(err);
});
},
jsonp(url, {
key: '騰訊地圖key',
address: address,
output: 'jsonp'
})
.then(res => {
console.log(res)
console.log(res)
const latitude = res.result.location.lat;
const longitude = res.result.location.lng;
console.log("res.result.location.lat: ",res.result.location.lat);
console.log("res.result.location.lng: ",res.result.location.lng);
this.$wx.openLocation({
latitude: latitude,
longitude: longitude,
name: this.address, // 位置名
address: this.address, // 地址詳情說明
scale: 15, // 地圖縮放級(jí)別,整型值,范圍從1~28。默認(rèn)為最大
infoUrl: '' ,// 在查看位置界面底部顯示的超鏈接,可點(diǎn)擊跳轉(zhuǎn)
});
})
.catch(err => {
console.log(err);
});
},
具體的參考騰訊開發(fā)文檔https://lbs.qq.com/service/webService/webServiceGuide/webServiceGeocoder文章來源地址http://www.zghlxwxcb.cn/news/detail-709284.html
到了這里,關(guān)于使用騰訊地圖獲取地址經(jīng)緯度的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!