I've built a web app using jQuery Mobile. My question is: using JS (jQuery or Vanilla), how can my web app detect if geolocation is disabled on a mobile device?
Asked
Active
Viewed 1,161 times
0
-
1Did you read this http://stackoverflow.com/questions/14862019/check-if-location-setting-has-been-turned-off-in-users-browser ? – Styx Aug 01 '15 at 10:19
-
That's exactly what I needed, and it worked perfectly. Thank you! P.S. Perhaps you should write this as an answer (maybe including a snippet of the code). If you do, I will mark it as the accepted answer. This way, it will be more visible to other people who are looking for this answer. – Liran H Aug 01 '15 at 12:34
-
Most suitable option is mark your question as duplicate, or edit it and point to the other answer I think. – Styx Aug 01 '15 at 18:32
1 Answers
1
Try Modernizr.
You can initialise with the tests you need, of which Geolocation is one of them.
As per the docs you can try something like this:
Modernizr.load({
test: Modernizr.geolocation,
yep : 'geo.js',
nope: 'geo-polyfill.js'
});
Where in this example it tests for geolocation and then selectively loads a javascript file depending on the result.
It will also add a .geolocation
class to the body DOM element if the device supports it, so you can simply test to see whether this class exists in order to determine if geolocation is supported / enabled.

Daniel Waghorn
- 2,997
- 2
- 20
- 33
-
Sorry, I should have mentioned, this web app is for a university assignment, and we are not allowed to use any plug-ins. Thanks for you help! – Liran H Aug 01 '15 at 12:35