The default source for geolocation in FF is set in about:config
from the parameter geo.wifi.uri to the value of https://www.google.com/loc/json
. When the standard geolocation call is made in Javascript, e.g., navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors); Firefox will query https://www.google.com/loc/json
with my IP address (desktop) and return my approximate location.
What I want to do is to set up a page on my own server that returns a specific geolocation; I'll hard code in the lat, lon, and accuracy value to be returned to my page that makes a getCurrentPosition call. This will let me test code for a client in various locations without actually having to go to those physical locations for testing.
Here is my problem: what format can I make my page so that it returns a valid structure / object that FF can use.
The page is hosted on Apache and will be generated from PHP.
For this example, let's say that my pseudo geolocation page is at http://mysite/json/index.php
.
I tried it with the following PHP code:
header('Content-type: application/json');
echo '{"position":'
. '{"coords":'
. '{'
. '"latitude":"80",'
. '"longitude":"-20",'
. '"altitude":"299",'
. '"accuracy":"111",'
. '"altitudeAccuracy":"222",'
. '"heading":"333",'
. '"speed":"44"'
. '}'
. '}'
. '}';
On my calling page I have the following javascript:
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_geolocation_query(position){
var foo = 'Lat: ' + position.coords.latitude + "\n"
+ 'Lon: ' + position.coords.longitude + "\n"
+ 'Alt: ' + position.coords.altitude + "\n"
+ 'Acc: ' + position.coords.accuracy + "\n"
+ 'AAc: ' + position.coords.altitudeAccuracy + "\n"
;
alert(foo);
}
function handle_errors(error) {
switch(error.code) {
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
With geo.wifi.uri set to https://www.google.com/loc/json
I get back my lat, lon, and accuracy as expected. When I change geo.wifi.uri to http://mysite/json
or to http://mysite.json/index.php
I get no apparent response, including no execution of the error section of the javascript.
I presume that the answer is in the geolocation-API but I can't make sense of it when all I really want is to return properly formatted information.
Any help on this will be appreciated.
TL;DR: what is required to generate a valid response for geo.wifi.uri as an alternative to https://www.google.com/loc/json
?