我尝试获取用户位置(权限步骤没有问题),但是Google用他的程序包react-native-geolocation-service和方法getCurrentPosition返回此方法:
{"coords": {"accuracy": 3, "altitude": 0, "heading": 0, "latitude": 0, "longitude": 0, "speed": 0}, "mocked": false, "timestamp": 1580744874000}
。
我使用此代码(来自官方文档的示例)。
在信中:
Geolocation.getCurrentPosition(
(position) => {
this.setState({ location: position, loading: false });
console.log(position);
},
(error) => {
this.setState({ location: error, loading: false });
console.log(error);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
添加到AndroidManifest.xml
您可能已经成功获得了位置许可,但是您确定设备已启用位置信息吗?
您可以使用此库来要求用户启用其GPS:https : //github.com/Richou/react-native-android-location-enabler
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句