question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing navigator.geolocation with GPS turned OFF in android > 6

See original GitHub issue

Hi,

im running an expo app,

im working on a react-native application, using expo and react-native-maps, and i need to get the latitude and longitud of the user current position.Im using navigator.geolocation API for thatwith the GPS turned on i have no problems, but i need to get the current position without GPS, based on the network provider.The problem is that when the application runs with expo on androiod > 6 i get this error:

21:50:53: Finished building JavaScript bundle in 449ms 21:50:55: Location services are disabled - node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:80:57 in - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:347:19 in __invokeCallback - … 4 more stack frames from framework internals

In IOs and android <=5 it works great.

class MyComponent extends Component {

    componentWillMount = () => {    
            this.getCurrentLocation();    
    }
    getCurrentLocation = () =>
         navigator.geolocation.getCurrentPosition(
            (position) => {
                let currentUserPosition = position.coords;
                alert(JSON.stringify(currentUserPosition));
            },
            (error) => {
                console.log(error);
            },
            {
                enableHighAccuracy: false,
                timeout: 20000,
                maximumAge: 0,
                distanceFilter: 10
            }
        );

}

And this are my package.json depencendies:

“dependencies”: { “expo”: “23.0.4”, “native-base”: “^2.3.5”, “react”: “16.0.0”, “react-native”: “0.50.4”, “react-native-extend-indicator”: “^0.1.2”, “react-native-maps”: “^0.19.0”, “react-native-maps-directions”: “^1.3.0”, “react-native-router-flux”: “4.0.0-beta.21”, “react-navigation”: “1.0.0-beta.21”, “react-navigation-redux-debouncer”: “^0.0.2”, “react-redux”: “^5.0.6”, “redux”: “^3.7.2”, }

expect that navigator.geolocation get the location based on the network provider in that situation (without gps), the specification saids that…

i also tried with the Geolocation API of expo (tried this example: https://snack.expo.io/@schazers/expo-map-and-location-example) , and with the GPS turned OFF i cant get my location…

is this related with expo? how can i enable location services on android when using the expo app?

thanks in advance

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
esamelsoncommented, Jan 27, 2018

Hi there - that error (Location services are disabled) is thrown if no location providers are available, i.e. the user has turned off location services on their device entirely. In this case, there is no way for an app to programmatically get any location information from the device. It sounds like what you want is to switch location services to the “Battery saving” mode, rather than turning them off entirely - have you tried that? https://support.google.com/accounts/answer/3467281?hl=en that should switch it to the network provider.

0reactions
esamelsoncommented, Feb 2, 2018

@marcosmartinez7 do you have a specific repro case (even another app or website) that successfully gets your wifi location while Location is turned off on the device?

I tried running the live example here https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation and I got Unable to retrieve location if I turned off Location.

We can add in the ability to request only ACCESS_COARSE_LOCATION, but I don’t think this will do what you want. The user will still need to turn on Location in order for your app to get a wifi location.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get current position without GPS on react-native with ...
The problem you are dealing with here is with EXPO, because the location request API has changed after Android 5(API 21).
Read more >
Manage your Android device's location settings
Turn location on or off for your phone · Swipe down from the top of the screen. · Touch and hold Location ....
Read more >
Get the last known location - Android Developers
Using the Google Play services location APIs, your app can request the last known location of the user's device. In most cases, you...
Read more >
Re: Function getGeolocation is not working on Android
I'm trying to use the function getGeolocation on Android, but this function is not working. Below is my code, but I don't have...
Read more >
Location - Expo Documentation
If you're using the iOS or Android Emulators, ensure that Location is enabled. Location ... This will turn off Wi-Fi location and only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found