Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2015 10:01
Show Gist options
  • Save anonymous/75f8a1b73a86d99257b1 to your computer and use it in GitHub Desktop.
Save anonymous/75f8a1b73a86d99257b1 to your computer and use it in GitHub Desktop.
Geolocation Test Harness Geolocation Test Harness // source https://jsbin.com/nupuyo
<!DOCTYPE html>
<meta name="robots" content="noindex">
<html>
<head>
<title>Geolocation Test Harness</title>
<meta name="description" content="Geolocation Test Harness">
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<title>chrome gps test</title>
<script>
var startTime = null;
var timer = null;
function log(mess, obj){
if (obj){
console.log(obj);
mess += JSON.stringify(obj);
}
if (!mess)
mess= "";
var d = new Date().getTime();
var str = (d-startTime) + " :: " + mess;
$(".results").append(str + "<br>");
console.log(str);
};
function runTest(enableHighAccuracy, maximumAge){
startTime = new Date().getTime();
var params = {enableHighAccuracy: enableHighAccuracy, timeout:2000, maximumAge: maximumAge};
timer = setTimeout(log, 500);
log("starting, params : ",params);
var success = function(position){
console.log(position);
var coords = {};
for ( var p in position.coords)
coords[p] = position.coords[p];
log("success", coords);
clearTimeout(timer);
};
var fail = function(err){
console.log(err);
log("fail ", {
code: err.code,
message: err.message
});
clearTimeout(timer);
};
navigator.geolocation.getCurrentPosition(success, fail, params);
};
function runTestLow(){
runTest(false);
}
function runTestHigh(){
runTest(true);
}
$(function(){
$(".go").on("click", function(ev){
var params = $(ev.currentTarget).data();
runTest(params.accuracy, params.age);
});
$(".clear").on("click", function(){
$(".results").empty("");
});
});
</script>
</head>
<body>
<h3>Geolocation Test Harness</h3>
<a href="https://twitter.com/zackster/">By Zac Spitzer @zackster</a>
<dl>
<dt>Firefox</dt>
<dd><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214482">On Firefox for Android, a non zero max age will often timeout, while 0 works with the same timeout</a></dd>
<dt>Chrome</dt>
<dd>
<a href="https://code.google.com/p/chromium/issues/detail?id=542923">when Geolocation unavailable, both TIMEOUT and POSITION_UNAVAILABLE are fired</a><br>
In chrome devtools, under emulation, check both <b>Emulate geolocation co-ordinates</b> and <b>Emulate position unavailable</n><br>
See <a href="http://stackoverflow.com/questions/29156164/does-chrome-violates-the-html5-standard-for-geolocation-api-when-position-is-una">Does Chrome violates the HTML5 standard for Geolocation API when position is unavailable?</a><br>
In addition, after using Emulate geolocation co-ordinates, once it's disabled, Chrome continues to return 0,0
</dd>
</dl>
<input type="button" class="go" value="low (age:2000)" style="font-size:20px;" data-age="2000" data-accuracy="false">
<input type="button" class="go" value="high (age:2000)" style="font-size:20px;" data-age="2000" data-accuracy="true">
<input type="button" class="go" value="low (age:0)" style="font-size:20px;" data-age="0" data-accuracy="false">
<input type="button" class="go" value="high (age:0)" style="font-size:20px;" data-age="0" data-accuracy="true">
<input type="button" class="clear" value="clear results" style="font-size:20px;">
<div class="results">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment