|
|
|
@ -6,7 +6,7 @@ import wxShareModel from "../models/wxShare-model.js"; |
|
|
|
import BMap from "BMap"; |
|
|
|
|
|
|
|
Vue.prototype.wxLocation = function () { |
|
|
|
wxShareModel.getWXCheck().then(response =>{ |
|
|
|
wxShareModel.getWXCheck().then(response => { |
|
|
|
if (response.code != 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -32,37 +32,38 @@ Vue.prototype.wxLocation = function () { |
|
|
|
}); |
|
|
|
wx.ready(() => { |
|
|
|
// 首次进入页面进会弹窗确认地理位置
|
|
|
|
// if (localStorage.getItem("latitude") == null) {
|
|
|
|
wx.getLocation({ |
|
|
|
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
|
|
success: function (res) { |
|
|
|
console.log('res:'+res); |
|
|
|
alert('res.latitude:'+res.latitude+'------res.longitude:'+res.longitude); |
|
|
|
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) { |
|
|
|
alert('data.result.location.lng:'+data.result.location.lng + '-----data.result.location.lat:'+data.result.location.lat); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
cancel: function () { |
|
|
|
alert("拒绝定位"); |
|
|
|
} |
|
|
|
}); |
|
|
|
// } else {
|
|
|
|
|
|
|
|
// }
|
|
|
|
if (localStorage.getItem("latitude") == null) { |
|
|
|
wx.getLocation({ |
|
|
|
type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
|
|
|
success: function (res) { |
|
|
|
console.log('res:' + res); |
|
|
|
// alert('res.latitude:' + res.latitude + '------res.longitude:' + res.longitude);
|
|
|
|
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) { |
|
|
|
// alert('data.result.location.lng:' + data.result.location.lng + '-----data.result.location.lat:' + data.result.location.lat);
|
|
|
|
localStorage.setItem("latitude", data.result.location.lat); |
|
|
|
localStorage.setItem("longitude", data.result.location.lng); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
cancel: function () { |
|
|
|
alert("拒绝定位"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
|
|
|
|
} |
|
|
|
// alert("lat:" + localStorage.getItem("latitude") + ";lng:" + localStorage.getItem("longitude"));
|
|
|
|
wx.error(function (res) { |
|
|
|
alert("wx-js初始化: " + res); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |