You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.6 KiB
63 lines
2.6 KiB
import Vue from "vue";
|
|
import wx from "weixin-js-sdk";
|
|
import axios from "axios";
|
|
import wxShareModel from "../models/wxShare-model.js";
|
|
//引入BMap
|
|
import BMap from "BMap";
|
|
|
|
Vue.prototype.wxLocation = function () {
|
|
wxShareModel.getWXCheck().then(response =>{
|
|
if (response.code != 0) {
|
|
return;
|
|
}
|
|
var jsApiSignConfig = response.response.jsApiSignConfig;
|
|
wx.config({
|
|
debug: false, // 开启调试模式,开发时可以开启
|
|
appId: jsApiSignConfig.appId, // 必填,公众号的唯一标识 由接口返回
|
|
timestamp: jsApiSignConfig.timestamp, // 必填,生成签名的时间戳 由接口返回
|
|
nonceStr: jsApiSignConfig.nonceStr, // 必填,生成签名的随机串 由接口返回
|
|
signature: jsApiSignConfig.signature, // 必填,签名 由接口返回
|
|
jsApiList: [
|
|
"onMenuShareAppMessage",
|
|
"onMenuShareTimeline",
|
|
"onMenuShareQQ",
|
|
"onMenuShareWeibo",
|
|
"onMenuShareQZone"
|
|
]
|
|
});
|
|
wx.ready(() => {
|
|
// 首次进入页面进会弹窗确认地理位置
|
|
if (localStorage.getItem("latitude") == null) {
|
|
wx.getLocation({
|
|
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
success: function (res) {
|
|
console.log('res:'+res);
|
|
localStorage.setItem("latitude", res.latitude);
|
|
localStorage.setItem("longitude", res.longitude);
|
|
$.ajax({
|
|
url: 'http://api.map.baidu.com/geocoder/v2/?ak=a79bFu054xIbE23jlynkSXX20F9yGD4G&callback=renderReverse&location=' + res.latitude + ',' + res.longitude + '&output=json&pois=1',
|
|
type: "get",
|
|
dataType: "jsonp",
|
|
jsonp: "callback",
|
|
success: function (data) {
|
|
console.log('data:'+data);
|
|
|
|
}
|
|
});
|
|
},
|
|
cancel: function () {
|
|
alter("拒绝定位");
|
|
}
|
|
});
|
|
} else {
|
|
|
|
}
|
|
alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude"));
|
|
wx.error(function (res) {
|
|
alter("wx-js初始化: " + res);
|
|
});
|
|
});
|
|
});
|
|
|
|
}
|
|
|