0

If Mobile's GPS is off, Then there will be prompt or toast or alert whatever will be shown

Please Enable your geolocation First.

I use something like this

if ("geolocation" in navigator) {
  /* geolocation is available */
} else {
  /* geolocation IS NOT available */
}

But this check only browser support GPS or not?

how can i do that ? Any Suggestions ?

1
  • Is this for a downloaded phone app, using Mozilla OS?
    – Adam
    Dec 17, 2014 at 23:06

1 Answer 1

2
+50

Clarifying the Question:

Here's the user flow which I understand from your question:

The user wants to use some part of your Mozilla OS app which requires GPS.
The app should check if the GPS is on.
If the GPS is off, prompt the user to turn their GPS on.

Code

(Based off of code from the Geolocation docs)

// geolocation is available  
if ("geolocation" in navigator) {

  // get position
  navigator.geolocation.getCurrentPosition(function(position) {
    do_something(position.coords.latitude, position.coords.longitude);
  });

// geolocation IS NOT available
} else {
  // notify the user to turn their GPS on
  new Notification("Please enable your GPS"); 

  /*Disable whatever feature you were planning on using until user comes back
   with the GPS turned on and this logic runs again.*/
}

Explanation

In Mozilla OS, developers do not have direct access to the GPS. Here's the research that led me to this conclusion:

After no mention on the Geolocation page, I looked on the "App permissions page" near the bottom in the section titled "Internal (Certified) app permissions". There is access to bluetooth, camera, and WiFi, but not GPS. Then I started looking at the Internal (Certified) settings page, where I found some additional hardware, but nothing regarding the GPS.

You already found the workaround on the Geolocation documentation page: you check to see if the Geolocation service will return a location. If it's undefined, then the GPS isn't turned on. Hacky, but that's what we've got.

If the GPS is off, you want to alert the user, asking to turn it on. According to the "App permissions page", in app development, you can notify the user in this way without asking for permission ("Allow for all installed App types") App permission picture

In the browser, you would have to ask to show notifications first using Notification.requestPermission().

The solution code given above is for Firefox OS 1.2+ (or Gecko 22+); if your app is using a earlier version, use mozNotification.

Summary (Anik's Specific Questions)

But this check only browser support GPS or not?

The same Geolocation service is used for browser and Mozilla OS apps. This is evidenced by the App Permission geolocation link to the Web API Interfaces Geolocation API page which says, "This allows a Web site or app to offer customized results based on the user's location." Regardless of the device type, "For privacy reasons, the user is asked for permission to report location information."

how can i do that ? Any Suggestions ?

See the code above and follow the many links to find sources for how to use the Geolocation service and create user notifications.

1
  • Thanks for your reply. I just wanna to sure that firefox still didn't provide the direct access to gps. track location from browser isn't accurate.Firefox have to work hard otherwise he won't survive in the long run with their current options. Dec 18, 2014 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.