我使用的是真正的 android 设备(5.1 版)
我可以使用 react-native-maps 确定我的位置(我的应用程序内 map 上正确的蓝点位置)+ 我可以使用谷歌地图应用程序并转到我的位置(GPS 工作)。
我正在使用大超时,将 enableHighAccuracy 切换为 true 和 false,删除选项......等等。均未能通过navigator.geolocation获取数据。
这是我的代码:
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
};
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
};
navigator.geolocation.getCurrentPosition(success, error, options);
我得到:错误(3):位置请求超时
最佳答案
我知道为时已晚,但它可以帮助其他人。
地理定位已从 React Native .60 版本中提取。如果您需要替代解决方案
安装 react-native-community/geolocation :
npm install @react-native-community/geolocation --save
react-native link @react-native-community/geolocation
然后,要请求访问位置,您需要将以下行添加到应用的 AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
用法:
import Geolocation from '@react-native-community/geolocation';
Geolocation.getCurrentPosition(info => console.log(info));
关于android - react native navigator.geolocation.getCurrentPosition 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47334159/