vue输出打印出当前经纬度
生活随笔
收集整理的這篇文章主要介紹了
vue输出打印出当前经纬度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
vue輸出打印出當前經緯度
我的思路當然還是去地圖的api上看看
我調用的高德地圖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即為當前所在城市信息console.log("通過ip獲取當前城市:", result);console.log("經緯度" + 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實現安裝騰訊地圖指令是:
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);總結
以上是生活随笔為你收集整理的vue输出打印出当前经纬度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么打开dpf文件
- 下一篇: html5倒计时秒杀怎么做,vue 设