0

I've written a web app for Firefox Mobile / Firefox OS. My app uses geolocation.

It worked well when I tested it with Firefox for Android and the FFOS simulator add-on by visiting the web address of the application. Recently I've passed the Firefox Marketplace review and my app is installable on FFOS and Firefox for Android. To my surprise, when I installed and ran it, geolocation didn't work.

Here's an excerpt from the .webapp file:

"permissions": {
    "geolocation": {
        "description": "Required for ....."
    }
}

Here's the relevant part of JS:

if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(positionFound, positionNotFound, {
        enableHighAccuracy: false,
        maximumAge: 3600000
    });
}
else {
    $('#location').html('No geolocation support');
}

The else block is not executed, so JS detects that geolocation exists, but the callback is never called, and the GPS icon never blinks.

The app still works and positionFound() is called properly when accessed via its URL, not as an installed app.

How can I make it geolocate after installation?

GDR
  • 2,301
  • 1
  • 21
  • 26
  • are positionFound and positionNotFound the callbacks you're referring to? – Charles380 Aug 08 '13 at 14:36
  • yes, they are callbacks. – GDR Aug 08 '13 at 17:09
  • Every time your app accesses your GPS position, Firefox OS asks for your permission (except if you checked last time for Firefox OS to remember your choice an not to ask again). Do you see a permission request dialog when your app launches and requests(/should request) geolocation? It looks [something like this](https://thelab.o2.com/wp-content/uploads/2013/06/situ.jpg). You should also check you Settings -> App permissions -> for the stored permissions I mentioned above. – Flaki Aug 10 '13 at 00:20
  • Also, are you sure that GPS is enabled in the Settings on the device? – Krzysztof Adamski Aug 12 '13 at 19:11
  • Krzysztof: I'm absolutely sure that GPS is enabled. Flaki: It doesn't request permission when installed as an app. It requests permission when accessed via URL. – GDR Aug 15 '13 at 09:42

2 Answers2

0

The following code works for us, however GPS functionality is severely limited on the Geeksphone FFOS 1.2 nightly builds as well as aGPS on FFOS 1.0 (time to first fix ~ 5min). The geoLocation API requires frequent reboots on our devices. For us, FFOS 1.1 worked best so far. Try to use one of the existing GPS apps like "gpsDashboard" before starting your app. This way you know your phone is working.

function geo_success(position) {
 alert(position.coords.longitude);
}

function geo_error() {
 alert("Sorry, no position available.");
}

var geo_options = {
 enableHighAccuracy: true,
 maximumAge : 300000,
 timeout : 270000
};

navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);

Do your callback functions work properly with fake data?

ti-
  • 1
  • My callback functions work properly with real data, when the "app" is started by entering an URL into browser. It's only broken when installed. – GDR Aug 27 '13 at 10:20
  • I would like to check with our code. Which FFOS version are you using? – ti- Aug 27 '13 at 11:10
  • Just Firefox for Android (which supports running FFOS apps) – GDR Aug 28 '13 at 09:16
0

Here's a post on the Mozilla Hacks Blog that discusses geolocation tips and tricks, as well as limitations with some of the developer devices:

https://hacks.mozilla.org/2013/10/who-moved-my-geolocation/