如何使用Geolocation在本机应用中获取设备的当前位置

时间:2018-05-04 08:07:53

标签: react-native geolocation

我是本机的新手,我希望获得设备的当前位置。我怎么能通过使用Geolocation这样做。我已经完成了本地文档的反应。但是我仍然无法获得该位置。

这是我的代码

我在AndroidManifest.xml中添加了以下行:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

这是我的代码到目前为止控制当前位置

        const location = Geolocation.getCurrentPosition();
        console.log("location", location)

(我在android中构建我的应用程序)

2 个答案:

答案 0 :(得分:0)

Geolocation.getCurrentPosition是异步的,因此location info is returned in callback

Geolocation.getCurrentPosition(location => console.log('location', location));

答案 1 :(得分:0)

遵循Configuration and Permissions部分,然后您可以使用:

1
  

作为浏览器polyfill,可通过navigator.geolocation全局使用此API-无需导入。