微信SDK授权经纬度,结合QQMap转中文地址
调用
import wxTool from '@/XXX/wxTool'
wxTool.getWXLocation(function (status) {
});
工具代码 wxTool.js
import wx from 'weixin-js-sdk'
import '@/xxx/qqmap'
import store from '@/module/index/store'
let initWXConfig = function (readyCallBack) {
let thisUrl = window.location.href;
api.getWXConfig({shareUrl : thisUrl}, function (isSuccess, data, err) {
if (isSuccess) {
wx.config({
debug: false,
appId: data.body.appId,
timestamp: data.body.timestamp,
nonceStr: data.body.nonceStr,
signature: data.body.sign,
jsApiList: ['getLocation']
});
wx.ready(function () {
readyCallBack(true);
});
wx.error(function (res) {
readyCallBack(false);
});
}else{
readyCallBack(false);
}
})
};
let initCityInfo = function (cityCode, cityName) {
store.commit('setCityCode','110100');
store.commit('setCityName', '北京市');
store.commit('setLatitude', '38');
store.commit('setLongitude', '110');
};
let getWXLocation = function (callBack) {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
initWXConfig(function (status) {
if (status) {
wx.getLocation({
type: 'gcj02',
success: function (res) {
let geocoder = new qq.maps.Geocoder({
complete: function (result) {
let provinceName = result.detail.addressComponents.province;
let cityName = result.detail.addressComponents.city;
let areaName = result.detail.addressComponents.district;
callBack('1');
}
});
var coord = new qq.maps.LatLng(res.latitude, res.longitude);
geocoder.getAddress(coord);
},
fail: function (res) {
initCityInfo();
}
});
} else {
initCityInfo();
}
})
}else{
initCityInfo();
}
};
export default {
getWXLocation
}
qqmap.js
window.qq = window.qq || {};
qq.maps = qq.maps || {};
window.soso || (window.soso = qq);
soso.maps || (soso.maps = qq.maps);
(function () {
function getScript(src) {
var protocol = (window.location.protocol == "https:") ? "https://" : "http://";
src = src && (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) ? src : protocol + src;
document.write('<' + 'script src="' + src + '"' +' type="text/javascript"><' + '/script>');
}
qq.maps.__load = function (apiLoad) {
delete qq.maps.__load;
apiLoad([["2.4.122","XXXXX-XXXXX-XXXXX-XXXXX-XXXXX",0],["https://3gimg.qq.com/","lightmap/api_v2/2/4/122/mods/","https://3gimg.qq.com/lightmap/api_v2/2/4/122/theme/",true],[1,18,34.519469,104.461761,4],[1565590588165,"https://pr.map.qq.com/pingd","https://pr.map.qq.com/pingd"],["https://apis.map.qq.com/jsapi","https://apikey.map.qq.com/mkey/index.php/mkey/check","https://sv.map.qq.com/xf","https://sv.map.qq.com/boundinfo","https://sv.map.qq.com/rarp","https://apis.map.qq.com/api/proxy/search","https://apis.map.qq.com/api/proxy/routes/","https://confinfo.map.qq.com/confinfo","https://overseactrl.map.qq.com"],[[null,["https://rt0.map.gtimg.com/tile","https://rt1.map.gtimg.com/tile","https://rt2.map.gtimg.com/tile","https://rt3.map.gtimg.com/tile"],"png",[256,256],3,19,"114",true,false],[null,["https://m0.map.gtimg.com/hwap","https://m1.map.gtimg.com/hwap","https://m2.map.gtimg.com/hwap","https://m3.map.gtimg.com/hwap"],"png",[128,128],3,18,"110",false,false],[null,["https://p0.map.gtimg.com/sateTiles","https://p1.map.gtimg.com/sateTiles","https://p2.map.gtimg.com/sateTiles","https://p3.map.gtimg.com/sateTiles"],"jpg",[256,256],1,19,"101",false,false],[null,["https://rt0.map.gtimg.com/tile","https://rt1.map.gtimg.com/tile","https://rt2.map.gtimg.com/tile","https://rt3.map.gtimg.com/tile"],"png",[256,256],1,19,"",false,false],[null,["https://sv0.map.qq.com/hlrender/","https://sv1.map.qq.com/hlrender/","https://sv2.map.qq.com/hlrender/","https://sv3.map.qq.com/hlrender/"],"png",[256,256],1,19,"",false,false],[null,["https://rtt2.map.qq.com/rtt/","https://rtt2a.map.qq.com/rtt/","https://rtt2b.map.qq.com/rtt/","https://rtt2c.map.qq.com/rtt/"],"png",[256,256],1,19,"",false,false],null,[["https://rt0.map.gtimg.com/vector/","https://rt1.map.gtimg.com/vector/","https://rt2.map.gtimg.com/vector/","https://rt3.map.gtimg.com/vector/"],[256,256],3,18,"114",["https://rt0.map.gtimg.com/icons/","https://rt1.map.gtimg.com/icons/","https://rt2.map.gtimg.com/icons/","https://rt3.map.gtimg.com/icons/"]],null],["https://s.map.qq.com/TPano/v1.1.2/TPano.js","map.qq.com/",""]],loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("https://3gimg.qq.com/lightmap/api_v2/2/4/122/main.js");
})();