更新获取位置,兼容非小程序模式
This commit is contained in:
parent
01860f4485
commit
8276edcb6f
@ -168,6 +168,7 @@
|
|||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '获取位置中'
|
title: '获取位置中'
|
||||||
})
|
})
|
||||||
|
if (uni.getStorageSync('uniMP')) {
|
||||||
uni.sendHostEvent('getLocation', '获取位置', (ret) => {
|
uni.sendHostEvent('getLocation', '获取位置', (ret) => {
|
||||||
uni.$on('uniMP_getLocation', (res) => {
|
uni.$on('uniMP_getLocation', (res) => {
|
||||||
try {
|
try {
|
||||||
@ -179,63 +180,31 @@
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
Toast('获取位置失败');
|
Toast('获取位置失败');
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
return ;
|
} else {
|
||||||
uni.getLocation({
|
uni.getLocation({
|
||||||
type: 'gcj02',
|
// type: 'gcj02',
|
||||||
geocode: true,
|
// geocode: true,
|
||||||
isHighAccuracy: true,
|
isHighAccuracy: true,
|
||||||
success: function async (res) {
|
highAccuracyExpireTime: 5 * 1000,
|
||||||
|
accuracy: 'best',
|
||||||
|
success: (res) => {
|
||||||
that.markers[1].latitude = res.latitude;
|
that.markers[1].latitude = res.latitude;
|
||||||
that.markers[1].longitude = res.longitude;
|
that.markers[1].longitude = res.longitude;
|
||||||
that.getDriverLine();
|
that.getDriverLine();
|
||||||
// uni.hideLoading();
|
uni.hideLoading();
|
||||||
console.log(res);
|
console.log(res);
|
||||||
uni.showModal({
|
|
||||||
title: '成功',
|
|
||||||
content: JSON.stringify(res)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
fail(e) {
|
fail(e) {
|
||||||
// uni.hideLoading();
|
uni.hideLoading();
|
||||||
Toast('获取位置失败');
|
Toast('获取位置失败');
|
||||||
console.log(e);
|
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() {
|
showToast() {
|
||||||
this.$refs.uToast.show({
|
this.$refs.uToast.show({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user