1***@qq.com
1***@qq.com
  • 发布:2024-11-01 17:02
  • 更新:2024-11-01 17:02
  • 阅读:93

在Android studio startLocationUpdate方法不执行不能获取位置

分类:uni-app

我的项目是用uni.startLocationUpdate和uni.onLocationChange实时获取位置,在hbuilderX里能正常获取位置,但是在Android studio中不能获取位置startLocationUpdate方法的success和fail都不运行,只运行complete,我使用的是手机自带定位安卓,且Android studio已配置获取定位权限

hbuilderX:getPosition() {
let that = this;
uni.getLocation({
type: 'wgs84',
success: function (res) {
that.newLocation.push({
lon:res.longitude,
lat:res.latitude
})
},
fail(res) {
}
});
uni.startLocationUpdate({
autoStop: false,
type: 'gcj02',
success: function(res) {
this.nowlocation = res.latitude
that.onLocationChange()
},
fail: function(res) {
console.log(res)
},
complete(res) {
// uni.showLoading({
// title: ${res.errMsg.split(':')[1]}
// });
}
});
},
onLocationChange() {
let that = this;
uni.onLocationChange(function(res) {
that.laton.lat = res.latitude.toFixed(6);
that.laton.lon = res.longitude.toFixed(6);
let lonlat = gcj02towgs84(res.longitude, res.latitude)
that.location = [lonlat[0], lonlat[1]]
});
},
failLocation(res){
this.nowlocation = res.errMsg
},

Android studio:AndroidManifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

2024-11-01 17:02 负责人:无 分享
已邀请:

要回复问题请先登录注册