简体   繁体   English

React-native android忽略navigator.geolocation.getCurrentPosition

[英]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.

相关问题 navigator.geolocation.getCurrentPosition在React Native中不起作用 - navigator.geolocation.getCurrentPosition is not working in React Native 反应本机 navigator.geolocation.getCurrentPosition 不起作用 - react native navigator.geolocation.getCurrentPosition not working 为什么 navigator.geolocation.getcurrentposition 不适用于 react native 和 expo - Why navigator.geolocation.getcurrentposition is not available with react native and expo navigator.geolocation.getCurrentPosition 在 Android 浏览器上失败 - navigator.geolocation.getCurrentPosition fails on Android Browser navigator.geolocation.getCurrentPosition在Android 7.0上不起作用 - navigator.geolocation.getCurrentPosition not working on Android 7.0 使用Cordova的navigator.geolocation.getCurrentPosition - navigator.geolocation.getCurrentPosition with Cordova navigator.geolocation.getCurrentPosition不适用于Android谷歌浏览器 - navigator.geolocation.getCurrentPosition doesn't work on android google chrome navigator.geolocation.getCurrentPosition() 永远不会在 Android 上的 WebView 中返回 - navigator.geolocation.getCurrentPosition() never returns in WebView on Android 在Android股票浏览器上navigator.geolocation.getCurrentPosition变慢 - navigator.geolocation.getCurrentPosition slow on Android stock browser navigator.geolocation.getCurrentPosition不会在Android上使用新位置重置 - navigator.geolocation.getCurrentPosition won't reset with new location on Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM