[英]React-native android ignores navigator.geolocation.getCurrentPosition
I'm trying to use navigator.geolocation.getCurrentPosition
on my Android device (Philips Xenium). 我正在尝试在我的Android设备(飞利浦Xenium)上使用
navigator.geolocation.getCurrentPosition
。 It works absolutely ok in iphone and genimotion simulator. 它在iphone和genimotion模拟器中完全可以正常工作。
navigator.geolocation.getCurrentPosition
returns absolutely nothing - no errors, no success. navigator.geolocation.getCurrentPosition
绝对没有返回 - 没有错误,没有成功。 However, if I turn off geolocation service in my smartphone, it returns No available location provider
. 但是,如果我在智能手机中关闭地理定位服务,则会返回“
No available location provider
。
Also, navigator.geolocation.watchPosition
works fine. 此外,
navigator.geolocation.watchPosition
工作正常。
Add the following permission to your AndroidManifest.xml file 将以下权限添加到AndroidManifest.xml文件中
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
and then pass an enableHighAccuracy object to your your geolocation.getCurrentPosition method: 然后将enableHighAccuracy对象传递给您的geolocation.getCurrentPosition方法:
navigator.geolocation.getCurrentPosition(
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
Make sure that Location is enabled in your device. 确保您的设备已启用“ 位置” 。
I enabled <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
, however I kept having the same error until I realized that location was disabled. 我启用了
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
,但是在我意识到该位置被禁用之前我一直有同样的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.