How do i check if location service is enabled?


I want to use


to get users current position, but before that need to make a check if user has enabled location service on his mobile…

Is there any geolocation service available for this?


From the appgyver api at

A Promise is resolved to the next available position data. Will wait for data for an indeterminate time; use a timeout if required.

So it seems you have to use $timeout to check if position has been returned, and execute alternative code in case it hasn’t. I had the same issue and couldn’t find any better solution.


Thanks Stephan, but that would still not give me precisely if location is enabled or not.


I had the same question, and couldn’t find an answer either. Here’s how I handled it, and the note I ended up putting in my controller, for everyone else’s reference…

// Start with the assumption that we do not have a location
var my_position = null;

// Now, request it.  If we get a location, update my_position
// NOTE: Appgyver/Supersonic have a way to request the user's position, but 
//		aparently have no way to determine whether the user has granted 
//		access to the device's location.  The only way to determine this 
//		information seems to be to infer it from whether you get a location.
//		Having said that, the getPosition() request seems to return almost 
//		instantaneously... so if we default the "near me" toggle to false/unchecked,
//		then we should have an answer by the time the user tries to turn it on.  
//		If my_position is still null when they flip the toggle, we will assume 
//		that they have not granted access to the device's location.
supersonic.device.geolocation.getPosition().then( function(position) {
	my_position = position;

I then have the following function to handle the user’s action when they try to change a toggle that says “find stuff near me”:

// When the user flips the "near me" toggle, check for location and 
// adjust other fields
    // If the user has flipped the toggle on...
    if ($("#near_me").is(":checked")) {
         // ...AND we have lat/lon coordinates...
         if (typeof(my_position.coords) === 'object') {
              // Do stuff
              // NOTE: the typeof() check is necessary because the getPosition()
              //         method seems to return an error if it doesn't get the 
              //         location.  So, checking if my_position is an object passes
              //         on success AND on error.  Checking if the "coords" object 
              //         exists within the presumed "my_position" object ensures that 
              //         getPosition() actually returned an object that contains 
              //         location information.
         } else {
             // Tell the user we don't have access
             supersonic.ui.dialog.alert("We Don't Have Your Location!", 
                      message: "You haven't given us access to your location.", 
                      buttonLabel: "Got it, thanks!"

Finally, again for reference, here’s my code from my view:

<label class="toggle toggle-positive">
    <input type="checkbox" id="near_me">
    <div class="track"><div class="handle"></div></div>
Find Places Near Me

I would love to know if anyone has a way to get ground truth on the user’s permissions decision, so that I don’t have to code on assumptions and inferences…