From b8528e1f82b1dd542ef7addeb5ddac59b67d1afd Mon Sep 17 00:00:00 2001 From: lfs3 Date: Wed, 28 Aug 2019 15:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/wxLocation.js | 59 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/models/wxLocation.js b/src/models/wxLocation.js index d543d26..fe14bfd 100644 --- a/src/models/wxLocation.js +++ b/src/models/wxLocation.js @@ -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); }); }); }); - - } - \ No newline at end of file + +}