地理位置在 React 本机项目中不起作用

Geolocation not working in React native project

我使用 expo 创建了一个项目:

expo init geotest

下一步安装库:

npm install react-native-geolocation-service

在app.json中添加权限:

"android": {
    "permissions": [
        "ACCESS_FINE_LOCATION"
    ]
}

App.js 包含以下代码:

https://github.com/Agontuk/react-native-geolocation-service/blob/master/example/App.js

但是当我调用 Geolocation.getCurrentPosition 时,我收到警告:

[Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNFusedLocation.getCurrentPosition')]

思路全部结束,请大家帮忙

我认为您应该使用 expo-location 并正确阅读文档。这是 link https://docs.expo.io/versions/latest/sdk/location/ 。如果您在执行此操作时遇到任何问题。然后随时问我。谢谢。