diff --git a/subpkg/property/vehicle.vue b/subpkg/property/vehicle.vue index 8e38a69..13d65c3 100644 --- a/subpkg/property/vehicle.vue +++ b/subpkg/property/vehicle.vue @@ -168,74 +168,43 @@ uni.showLoading({ title: '获取位置中' }) - uni.sendHostEvent('getLocation', '获取位置', (ret) => { - uni.$on('uniMP_getLocation', (res) => { - try { - if(!res.latitude)new Error(); + if (uni.getStorageSync('uniMP')) { + uni.sendHostEvent('getLocation', '获取位置', (ret) => { + uni.$on('uniMP_getLocation', (res) => { + try { + if (!res.latitude) new Error(); + that.markers[1].latitude = res.latitude; + that.markers[1].longitude = res.longitude; + that.getDriverLine(); + uni.hideLoading(); + } catch (e) { + uni.hideLoading(); + Toast('获取位置失败'); + console.log(e); + } + }) + }); + } else { + uni.getLocation({ + // type: 'gcj02', + // geocode: true, + isHighAccuracy: true, + highAccuracyExpireTime: 5 * 1000, + accuracy: 'best', + success: (res) => { that.markers[1].latitude = res.latitude; that.markers[1].longitude = res.longitude; that.getDriverLine(); uni.hideLoading(); - } catch (e) { + console.log(res); + }, + fail(e) { uni.hideLoading(); Toast('获取位置失败'); + console.log(e); } - }) - }); - return ; - uni.getLocation({ - type: 'gcj02', - geocode: true, - isHighAccuracy: true, - success: function async (res) { - that.markers[1].latitude = res.latitude; - that.markers[1].longitude = res.longitude; - that.getDriverLine(); - // uni.hideLoading(); - console.log(res); - uni.showModal({ - title: '成功', - content: JSON.stringify(res) - }) - }, - fail(e) { - // uni.hideLoading(); - Toast('获取位置失败'); - console.log(e); - uni.showModal({ - title: '失败', - content: JSON.stringify(e) - }) - try { - plus.geolocation.getCurrentPosition(function(position) { - console.log('经度:' + position.coords.longitude); - console.log('纬度:' + position.coords.latitude); - that.markers[1].latitude = position.coords.longitude; - that.markers[1].longitude = position.coords.longitude; - that.getDriverLine(); - uni.hideLoading(); - uni.showModal({ - title: 'plus成功', - content: JSON.parse(position) - }) - }, function(error) { - console.error('获取位置失败:', error.message); - uni.showModal({ - title: 'plus失败', - content: JSON.parse(error) - }) - - }); - } catch (e) { - uni.showModal({ - title: '没有plus', - content: JSON.parse(e) - }) - } - } - }); - - + }); + } }, showToast() { this.$refs.uToast.show({