Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native android ignores navigator.geolocation.getCurrentPosition

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.

like image 965
stkvtflw Avatar asked Feb 01 '16 08:02

stkvtflw


1 Answers

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}
);
like image 88
Orlando Avatar answered Nov 04 '22 16:11

Orlando