As you certainly already know, Firefox 3.5 includes a geolocation provider based on Google APIs. It allows to retrieve the user's latitude and longitude, and Doug Turner recently added support for reverse geolocation. Very cool.

But to use this in recent xulrunner builds, you need a few things and geolocation will not work without them:

  1. you need a pref to enable geolocation
    pref("geo.enabled", true);
  2. You need a pref to specify Google geolocation API
    pref("geo.wifi.uri", "");
  3. You also need a JS component derived from lines 1036 and following in nsBrowserGlue.js. The minimal component you need, if you want to always allow geolocation requests without prompting the user about it, is the following one:
    const Ci = Components.interfaces;
    const Cc = Components.classes;
    const Cr = Components.results;
    const Cu = Components.utils;


    function GeolocationPrompt() {}

    GeolocationPrompt.prototype = {
    classDescription: "Geolocation Prompting Component",
    classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
    contractID: ";1",

    QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),

    prompt: function(request) {

    //module initialization
    function NSGetModule(aCompMgr, aFileSpec) {
    return XPCOMUtils.generateModule([GeolocationPrompt]);

If you need more than that, just tweak the prompt method above and do a request.allow() or request.cancel() depending on your wishes.

All the above done, you can safely query navigator.geolocation.getCurrentPosition.