问题
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