更新获取位置,兼容非小程序模式
This commit is contained in:
parent
01860f4485
commit
8276edcb6f
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user