我已经阅读并测试了很多问题,但仍然无法在Android上进行地理位置定位。
[我使用navigator.geolocation.getCurrentPosition,在iOS上一切正常,但是在Android上,我对此功能没有任何答案,无论成功还是错误。
我已经安装了react-native-permissions以确保用户已激活权限,但是它没有更改任何内容,因为它说所有内容都是“授权的”。
我注意到它来自设备的GPS。如果我手动激活它,则一切正常。但是,我找不到为用户激活它的方法。在iOS上,如果未激活GPS,我会进入错误回调并告诉用户将其激活,但是在android上,则什么也没有发生。
我不明白为什么我不能仅使用getCurrentPosition进行地理位置定位(清单中有ACCESS_COARSE_LOCATION和ACCESS_FINE_LOCATION)。
这是我的代码的一部分:
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
//do my stuff with position value
},
(error) => {
Permissions.getPermissionStatus('location')
.then((response) => {
if (response !== "authorized") {
Alert.alert(
"Error",
"We need to access to your location",
[
{
text: "Cancel",
onPress: () => {
// do my stuff
}, style: 'cancel'
},
{
text: "Open Settings",
onPress: () => Permissions.openSettings()
}
]
);
} else {
// do my stuff
}
});
},
{ enableHighAccuracy: true, timeout: 2000, maximumAge: 1000 }
);
}
有人有什么想法吗?
谢谢
您应该需要在Android上启用GPS