vue输出打印出当前经纬度
生活随笔
收集整理的這篇文章主要介紹了
vue输出打印出当前经纬度
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
vue輸出打印出當(dāng)前經(jīng)緯度
我的思路當(dāng)然還是去地圖的api上看看
我調(diào)用的高德地圖api
高德地圖api鏈接: link.https://lbs.amap.com/api/javascript-api/reference/location
來人,上代碼~
// 高德地圖api created(){var that = this;AMap.plugin("AMap.CitySearch", function() {var citySearch = new AMap.CitySearch();citySearch.getLocalCity(function(status, result) {if (status === "complete" && result.info === "OK") {// 查詢成功,result即為當(dāng)前所在城市信息console.log("通過ip獲取當(dāng)前城市:", result);console.log("經(jīng)緯度" + result.bounds.Gb.lat);that.lat = result.bounds.Gb.lat;that.lng = result.bounds.Gb.lat;}});});},騰訊地圖api鏈接: link.https://lbs.qq.com/tool/component-geolocation.html
1.vue實(shí)現(xiàn)安裝騰訊地圖指令是:
npm install weixin-js-sdk --save
2.然后main.js引入
import wxsdk from 'weixin-js-sdk';Vue.use(wxsdk);3.index.js寫入(替換自己的key)
<iframe id="geoPage" width=0 height=0 frameborder=0 style="display:none;" scrolling="no"src="https://apis.map.qq.com/tools/geolocation?key=your key&referer=myapp"> </iframe>4.然后就可以引入使用了
window.addEventListener('message', function(event) {// 接收位置信息var loc = event.data;console.log('location', loc); }, false);總結(jié)
以上是生活随笔為你收集整理的vue输出打印出当前经纬度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么打开dpf文件
- 下一篇: vue百度地图API、获取当前经纬度以及