我已经阅读并测试了很多问题,但我仍然无法在 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 …
Run Code Online (Sandbox Code Playgroud)