Accessing navigator.geolocation with GPS turned OFF in android > 6
See original GitHub issueHi,
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:
- Created 6 years ago
- Comments:12 (6 by maintainers)
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.@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.