首页 > 解决方案 > 地理位置在 React 本机项目中不起作用

问题描述

我使用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')]

所有想法都结束了,请帮助。

标签: javascriptandroidreact-nativegeolocationfrontend

解决方案


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


推荐阅读