React-native android会忽略navigator.geolocation.getCurrentPosition [英] React-native android ignores navigator.geolocation.getCurrentPosition
问题描述
我正尝试在Android设备(Philips Xenium)上使用 navigator.geolocation.getCurrentPosition
。它在iPhone和genimotion模拟器中绝对可行。
navigator.geolocation.getCurrentPosition
绝对没有返回 - 没有错误,没有成功。
但是,如果我在智能手机中关闭了地理定位服务,它将返回没有可用的位置提供商
。
navigator.geolocation.watchPosition
可以正常工作。 您的AndroidManifest.xml文件的以下权限
<使用权限android:name =android.permission.ACCESS_FINE_LOCATION/ >
,然后将enableHighAccuracy对象传递给您的geolocation.getCurrentPosition方法:
navigator.geolocation.getCurrentPosition(
{enableHighAccuracy:true,timeout:20000,maximumAge:1000}
);
I'm trying to use navigator.geolocation.getCurrentPosition
on my Android device (Philips Xenium). It works absolutely ok in iphone and genimotion simulator.
navigator.geolocation.getCurrentPosition
returns absolutely nothing - no errors, no success.
However, if I turn off geolocation service in my smartphone, it returns No available location provider
.
Also, navigator.geolocation.watchPosition
works fine.
Add the following permission to your AndroidManifest.xml file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
and then pass an enableHighAccuracy object to your your geolocation.getCurrentPosition method:
navigator.geolocation.getCurrentPosition(
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
这篇关于React-native android会忽略navigator.geolocation.getCurrentPosition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!