React-native android ignores navigator.geolocation.getCurrentPosition

☆樱花仙子☆ 提交于 2019-12-05 10:46:32

问题


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.


回答1:


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}
);



回答2:


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.



来源:https://stackoverflow.com/questions/35126349/react-native-android-ignores-navigator-geolocation-getcurrentposition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!