React-native android ignores navigator.geolocation.getCurrentPosition
Asked Answered
A

2

17

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.

Ananna answered 1/2, 2016 at 8:55 Comment(6)
Did you ever solve this? I got the exact same issue..Voleta
Same here. And I can't show the current location on a map, which I imagine is the same issueSpalding
I have had the same strange issue. It worked for me when I put the device's position-settings to high-accuracy or battery-saving (wifi + cellular), but not when the setting was device only (GPS).Redbreast
Did anyone find a resolution to this issue? I'm running into the same issue.Erdman
Are you testing inside a building? If yes can you just try to test it outside where you have a better reception and see if it works?Nuristan
I'm having the same issue only with certain phones... works with Samsung S7 for ex. (tested on android 6 + 7) but doesn't work on samsung S5 with android 5.0Inarticulate
N
3

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}
);
Nuristan answered 5/7, 2016 at 10:14 Comment(0)
M
1

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.

Misrule answered 24/7, 2016 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.