By default, the geolocation source in FF is set to about:configfrom the geo.wifi.uri parameter https://www.google.com/loc/json. When a standard geolocation call is made in Javascript, for example, navigator.geolocation.getCurrentPosition (handle_geolocation_query, handle_errors); Firefox will query https://www.google.com/loc/jsonwith my IP address (desktop) and return an approximate location.
What I want to do is set up a page on my own server that returns a specific geolocation ; I will hardcode the lat, lon value and the precision that will be returned to my page, which will call getCurrentPosition. This will allow me to test the code for the client in different places, without having to go into these physical places for testing.
Here is my problem: in 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.
In this example, suppose 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 call 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;
}
}
geo.wifi.uri https://www.google.com/loc/json , , . geo.wifi.uri http://mysite/json http://mysite.json/index.php, , javascript.
, geolocation-API, , , , - .
.
TL; DR: geo.wifi.uri https://www.google.com/loc/json?