高德,微信公众号,企业微信获取定位
生活随笔
收集整理的這篇文章主要介紹了
高德,微信公众号,企业微信获取定位
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
微信公眾號開發文檔:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
高德文檔:https://lbs.amap.com/api/javascript-api/reference-amap-ui/other/positionpicker
1.高德地圖:?
1-1.獲取當前定位信息
AMap.plugin(['AMap.Geolocation'], ()=> { const geolocation = new AMap.Geolocation({timeout: 10000});map.addControl(geolocation);geolocation.getCurrentPosition( (status, result) =>{if (status == 'complete') {onComplete(result)} else {onError(result)}});})1-2.?根據經緯度獲取定位信息
function getWGSLocation(locationarg){ // 傳入經緯度,格式:`${longitude},${latitude}`return new Promise(function(resolve, reject){AMap.convertFrom(locationarg,"gps",(status, result) => { // WGS84 轉高德if (status.toLowerCase() === 'complete' && result.info.toLowerCase() === 'ok') {const lon = result.locations[0].getLng();const lat = result.locations[0].getLat();geocoder.getAddress([lon, lat],(s, r) => {if (s.toLowerCase() === 'complete' && r.info.toLowerCase() === 'ok') {resolve(r)} else {console.log('error'); }});} else {console.log('error');}});}) }2.微信公眾號獲取定位:
2-1.配置wx.config(為了安全,所有信息要從服務端獲取)
import wx from 'weixin-jsapi'; //npm安裝weixin-jsapi 或者直接頁面引用// 通過后端的接口拿到appid,簽名...等信息,注:當前頁面的href不可以有#,否去取不到 axios.post('/Home/GetWxJsSdkParam', {url:location.href.split('#')[0]}).then((response) => {const c = res;wx.config({beta: true,// 必須這么寫,否則wx.invoke調用形式的jsapi會有問題// debug: true, // 開啟調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時才會打印。appId: c.AppId, // 必填,企業號的唯一標識,此處填寫企業號corpidtimestamp: c.TimeStamp, // 必填,生成簽名的時間戳nonceStr: c.NonceStr, // 必填,生成簽名的隨機串signature: c.Sign,// 必填,簽名,見附錄1jsApiList: ['getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2 }); })2-2.獲取當前位置的經緯度,然后根據微信返回的經緯度,調用上面高德地圖的1-2的getWGSLocation方法
const that = this;wx.getLocation({type: 'wgs84', // 默認為wgs84的gps坐標,如果要返回直接給openLocation用的火星坐標,可傳入'gcj02'success: function (res) {console.log(res)const latitude = res.latitude; // 緯度,浮點數,范圍為90 ~ -90const longitude = res.longitude; // 經度,浮點數,范圍為180 ~ -180。 // `${longitude},${latitude}`getWGSLocation(longitude+','+latitude).then((r)=>{console.log(r);// 獲取的具體位置信息; })},fail:function(err){console.log('微信調用失敗哦');console.log(err); }});3.企業微信(同微信公眾號)
轉載于:https://www.cnblogs.com/darkbluelove/p/11376045.html
總結
以上是生活随笔為你收集整理的高德,微信公众号,企业微信获取定位的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 训练计划安排(练一休一训练分化+倒金字塔
- 下一篇: 图片框