Geolocation provider for Firefox that allows manual input
Asked Answered
I

7

19

Are there any easy ways to override the default behaviors of the geolocation api and just hard code your current location?

I think this would be useful for testing and for privacy reasons (providing fake location data)

I thought there was an add on for this but I can't seem to find one. Only option right now seems to be changing the about:config geo.wifi.url to some alternative webservice, which I consider overly complicated.

Any ideas?

Thanks

Ideal Scenario

Somebody implements an add-on where a google map appears and I can pick a new default location.

Islek answered 26/11, 2009 at 0:55 Comment(1)
Such an ideal scenario has materialized - there's a Manual Geolocation chrome extension on the chrome webstore now.Pontic
R
12

The geo.wifi.uri does not need to be a webservice. You can also set it to a local uri with file://...

The file should be a json file with content like this:

{"location": {
              "latitude": 48.777025000000002, 
              "longitude": 9.1713909999999998, 
              "accuracy": 10.0}}

Update: For Firefox 9+, the format has changed:

{
    "status": "OK",
    "accuracy": 10.0,
    "location": {"lat": 48.777, "lng": 9.171}
}

Or you can combine them to support both:

{
    "status": "OK",
    "accuracy": 10.0,
    "location": {
        "lat": 48.777,
        "lng": 9.171,
        "latitude": 48.777,
        "longitude": 9.171,
        "accuracy": 10.0
    }
}

Update: it looks like manually setting this preference is blocked by the provider assuming the Google service. See Bug 716453 Update 2: geo.wifi.uri not geo.wifi.url

Ruffle answered 15/12, 2009 at 23:42 Comment(0)
R
14

The easiest way is to navigate to about:config and then in the filter box enter geo.wifi.uri, double-click the only config row that shows up, and enter the value below after you replace xxx and yyy with the co-ordinates you get from a service like http://www.getlatlon.com/:

data:application/json,{"location":{"latitude":xxx,"longitude":yyy,"accuracy":10}}

This trick doesn't require any add-ons or local/hosted files. Make sure the value is without any spaces and is on a single line!

Rachellerachis answered 13/4, 2011 at 3:55 Comment(3)
For reference, the default value of this field is geoloc://www.google.com/loc/jsonCleotildeclepe
in Firefox 10+ use this data:application/json,{"location":{"lat":xxx,"lng":yyy,"accuracy":10}}Cunctation
Actually, these days, it's data:application/json,{"location":{"lat":xxx,"lng":yyy},"accuracy":10}Taxpayer
R
12

The geo.wifi.uri does not need to be a webservice. You can also set it to a local uri with file://...

The file should be a json file with content like this:

{"location": {
              "latitude": 48.777025000000002, 
              "longitude": 9.1713909999999998, 
              "accuracy": 10.0}}

Update: For Firefox 9+, the format has changed:

{
    "status": "OK",
    "accuracy": 10.0,
    "location": {"lat": 48.777, "lng": 9.171}
}

Or you can combine them to support both:

{
    "status": "OK",
    "accuracy": 10.0,
    "location": {
        "lat": 48.777,
        "lng": 9.171,
        "latitude": 48.777,
        "longitude": 9.171,
        "accuracy": 10.0
    }
}

Update: it looks like manually setting this preference is blocked by the provider assuming the Google service. See Bug 716453 Update 2: geo.wifi.uri not geo.wifi.url

Ruffle answered 15/12, 2009 at 23:42 Comment(0)
E
5

Geolocater is an experimental add-on that lets you edit your geolocation.

Eth answered 24/3, 2010 at 18:37 Comment(0)
E
0

Hmmm, you can't mock navigator.geolocation directly - perhaps you can refactor your code that uses it to use another object - say customGeoLocation.

In production you can just set customGeoLocation to navigator.geolocation and in tests use a mock implementation of whatever functionality you use.

EDIT: Turns out you can replace functions on navigator.geolocation object but that is still useless if you are using a mock library (like JsMock) which needs to create a mock object. So you wouldn't be able to replace navigator.geolocation with a mock.

You can do the mocking yourself in this fashion:

var getCurrentPositionCalled = false;
navigator.geolocation.getCurrentPosition = function() { 
  getCurrentPositionCalled = true; 
};

//Your app code here
//...
assert(getCurrentPositionCalled);
Eyewash answered 26/11, 2009 at 1:5 Comment(0)
V
0

I have wired up Google Latitude to Firefox geolocation. This lets you manually update your location in Google Latitude with a single mouse click, instead of looking up your latitude and longitude yourself and typing it into a local file. My article on the subject is Make Firefox Take Geolocation From Google Latitude.

The solution required a small amount of server-side coding (I provide source code in the article), but I am for the time being running this code as a free live service that you can use.

Cheers, MetaEd

Voyageur answered 30/11, 2010 at 5:25 Comment(0)
P
0

In Chrome, you can use the Manual Geolocation chrome extension. It'll let you graphically choose your manual location.

Pontic answered 8/1, 2012 at 9:1 Comment(0)
S
0

I have created a simple web application that serves as a geolocation endpoint you can point the browser's geo.wifi.uri to. It is compatible with the Google API specification. To use it, just enter the following, replacing [latitude] and [longitude] with the desired values:

http://geolocation-mocker.phitherek.me/geolocate/[latitude]/[longitude]

and it should work. To check if the service is up, navigate to

http://geolocation-mocker.phitherek.me

and check if the HTML page displays correctly. You can find the source code for this simple app at

https://github.com/Phitherek/geolocation-mocker

I hope this tool will prove to be useful.

Swat answered 6/5, 2016 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.