From fb022a9b0429cb7c26938855b07e7bf80e4dda63 Mon Sep 17 00:00:00 2001 From: hly <2783385703@qq.com> Date: Fri, 29 Aug 2025 17:06:28 +0800 Subject: [PATCH] 1 --- pages_order/auth/wxLogin.vue | 6 +- utils/position.js | 146 ------------------------------------------- 2 files changed, 3 insertions(+), 149 deletions(-) diff --git a/pages_order/auth/wxLogin.vue b/pages_order/auth/wxLogin.vue index f7b1d05..59cff3a 100644 --- a/pages_order/auth/wxLogin.vue +++ b/pages_order/auth/wxLogin.vue @@ -8,11 +8,11 @@ - + - 授权登录 + 手机号快捷登录 diff --git a/utils/position.js b/utils/position.js index 26210b6..dc752b4 100644 --- a/utils/position.js +++ b/utils/position.js @@ -31,154 +31,8 @@ function calculateDistance(lat1, lon1, lat2, lon2, fixed = 0) { //计算两点 return distance.toFixed(fixed) } -function getLocation(fn) { //获取用户经纬度 - wxGetLocation() //此方法只用于提示用户打开gps - uni.getLocation({ - type: 'gcj02', - isHighAccuracy: true, - highAccuracyExpireTime: 1000, - success: function(position) { - fn(position) - }, - fail: function() { //使用ip获取定位 - let key = config.mapKey; //腾讯地图key - getUserAddressByIp(key).then(res => { - fn(res.position) //返回经纬度 - }) - } - }) -} - -function getLocationDetail() { //获取用户详细地址 - wxGetLocation() - return new Promise((resolve, reject) => { - let key = config.mapKey; //腾讯地图key - uni.getLocation({ - type: 'gcj02', - isHighAccuracy: true, - highAccuracyExpireTime: 1000, - success: function(position) { - getUserAddress(position.latitude, position.longitude, key).then(res => { - resolve(res) - }) - }, - fail: function() { //使用ip获取定位 - getUserAddressByIp(key).then(res => { - resolve(res) - }) - } - }) - }) -} - -function getUserAddress(latitude, longitude, key) { //通过经纬度获取用户详细地址 - return new Promise((resolve, reject) => { - - let url = `/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}` - - // #ifndef H5 - url = `https://apis.map.qq.com` + url - // #endif - - uni.request({ - url, - success: (res) => { - let { - lat, - lng - } = res.data.result.ad_info.location; - let data = { - position: { - latitude: lat, - longitude: lng - }, - addressDetail: res.data.result.ad_info - } - resolve(data) - }, - fail(err) { - reject(err) - } - }) - }) -} - -function getUserAddressByIp(key) { //根据IP获取当前用户位置 - return new Promise((resolve, reject) => { - uni.request({ - url: 'https://api.ipify.org?format=json', - success: (ipInfo) => { - - let url = `/ws/location/v1/ip?ip=${ipInfo.data.ip}&key=${key}` - - // #ifndef H5 - url = `https://apis.map.qq.com` + url - // #endif - - uni.request({ - url, - success: (res) => { - let { - lat, - lng - } = res.data.result.location; - let data = { - addressDetail: res.data.result.ad_info, - ip: res.data.result.ip, - position: { - latitude: lat, - longitude: lng - } - } - resolve(data) - }, - fail(err) { - reject(err) - } - }) - } - }) - }) -} - -//打开地图让用户选择位置 -function selectAddress(longitude, latitude, successCallback) { - uni.chooseLocation({ - // longitude, //经度 - // latitude, //纬度 - success: function(res) { - successCallback && successCallback(res) - } - }); -} - -//sdk自带获取位置方法(只支持微信环境),这里只当提示在用了(具体获取地址逻辑上面几个方法已完成) -function wxGetLocation(successCallback, failCallback) { - // #ifdef MP-WEIXIN - - // #endif - console.log('wx.getLocation'); - wx.getLocation({ - type: 'gcj02', - isHighAccuracy: true, - highAccuracyExpireTime: 2000, - success(res) {}, - fail(err) { - if(err.errMsg == 'getLocation:gps closed'){ - uni.showToast({ - title: '请打开GPS定位,否则定位不准确', - icon: 'none' - }) - } - } - }) -} export default { calculateDistance, //计算两点距离 - getLocationDetail, //获取用户详细地址 - getLocation, //获取用户经纬度 - selectAddress, //打开地图让用户选择位置 - wxGetLocation, } \ No newline at end of file