Is there a way to determine if location services using JavaScript are enabled on my mobile device?

I am currently using Modernizr to determine if geolocation is supported for a specific device. However, I want to show a more specific error message if geolocation is supported, but the user has disabled location services for his device.

I receive complaints that geolocation does not work on supported browsers, when in fact it is just that the user did not enable them.

I know there are ways to detect this using my own mobile code, but is there a way to do this using JavaScript? Does Modernizr support this?

+4
source share
1 answer

Is your error callback being executed? If you don’t have one, try adding it. If it never fires, you can set a timeout in your function so that if it does not receive permission for a certain period of time, to display a notification.

Since errorCallback never fails if geo is disabled, create a wrapper around the function that will create the setting for another function. If any of the api callbacks are triggered, then remove the setting before it starts working.

var timeOutId; function disabledGeoHandler(){...} function show_map() { clearTimeout(timOutId); ... } function show_map_error() { clearTimeout(timOutId); ... } function lookup_location() { timeOutId = setTimeout(disabledGeoHandler, 1000); navigator.geolocation.getCurrentPosition(show_map, show_map_error); } 

In fact, you can just use geo.js

+5
source

All Articles