項(xiàng)目背景:vue2.0似将,路由為hash模式
問(wèn)題描述:微信公眾號(hào)開(kāi)發(fā)获黔,調(diào)起微信內(nèi)置地圖、安卓一切正常在验,ios下會(huì)調(diào)用失敗
解決方法:
首先確保自己簽名算法正確玷氏,jsconfig都配置正確
1.經(jīng)緯度必須是number類型的值,不能是 字符串
2.IOS中jsconfig的url地址使用“#”(路由為hash模式)前面的路徑
即window.location.href.split('#')[0]
下面貼出自己的代碼(代碼不全腋舌,只貼出上面說(shuō)到兩條問(wèn)題的處理代碼)
//調(diào)起微信內(nèi)置地圖方法
openWxMap(ev){
const that = this;
const appId = sessionStorage.getItem('appId');
const position = ev.target.dataset;
//const url = window.location.href;
const url = window.location.href.split('#')[0]; //解決ios下無(wú)法調(diào)起內(nèi)置地圖問(wèn)題
const lat = parseFloat(position.lat); //轉(zhuǎn)為number類型值
const lng = parseFloat(position.lng);//轉(zhuǎn)為number類型值
const name = position.name;
const addres = position.address;
//getJsConfig方法是自己封裝的方法
that.$request.getJsConfig({appid:appId, jsurl: url}, res => {
const data = res;
that.$helper.wxConfig(data, () => {
wx.openLocation({
latitude: lat, // 緯度盏触,浮點(diǎn)數(shù),范圍為90 ~ -90
longitude: lng, // 經(jīng)度侦厚,浮點(diǎn)數(shù)耻陕,范圍為180 ~ -180。
name: name, // 位置名
address: addres, // 地址詳情說(shuō)明
scale: 15, // 地圖縮放級(jí)別,整形值,范圍從1~28刨沦。默認(rèn)為最大
infoUrl: '' // 在查看位置界面底部顯示的超鏈接,可點(diǎn)擊跳轉(zhuǎn)
});
});
})
},