<!DOCTYPE html>
<html>
<head>
<title>
    Test
</title>
</head>
<body>

<div id="output">
output
</div>

<script type="text/javascript">
var outputDiv = document.getElementById('output');
if (/http:/.test(window.location)) {
    var newUrl = 'https://' +
        window.location.hostname +
        ':4443'
        window.location.pathname +
        window.location.hash;
    outputDiv.innerHTML = '<a href="' + newUrl + '">Click for HTTPS</a>';
} else {
    var watchID = navigator.geolocation.watchPosition(function(position) {
        var params = '/post';
        var coordsUl = document.createElement('ul');
        for (key in position.coords) {
            params += ('&' + key + '=' + position.coords[key]);
            var coordsLi = document.createElement('li');
            coordsLi.innerHTML = key + ': ' + position.coords[key];
            coordsUl.appendChild(coordsLi);
        }
        params = params.replace('&', '?');
        outputDiv.innerHTML = '';
        outputDiv.appendChild(coordsUl);

        var request = new XMLHttpRequest();
        request.open('GET', params);
        request.send();
    });
}

</script>

</body>
</html>

<!DOCTYPE html>
<html>
<head>
<title>
    Test
</title>
</head>
<body>

<div id="output">
output
</div>
<div id="error">
error
</div>

<!-- TODO: Add buttons to start and cancel watchPosition -->

<script type="text/javascript">
var outputDiv = document.getElementById('output');
if (/http:/.test(window.location)) {
    var newUrl = 'https://' +
        window.location.hostname +
        ':4443'
        window.location.pathname +
        window.location.hash;
    outputDiv.innerHTML = '<a href="' + newUrl + '">Click for HTTPS</a>';
} else {
    var watchID = navigator.geolocation.watchPosition(function(position) {
        var params = '/post';
        var coordsUl = document.createElement('ul');

        function addStuff(key, value) {
            params += ('&' + key + '=' + value);
            var coordsLi = document.createElement('li');
            coordsLi.innerHTML = key + ': ' + value;
            coordsUl.appendChild(coordsLi);
        }
        for (key in position.coords) {
            addStuff(key, position.coords[key]);
        }
        addStuff('timestamp', String(position.timestamp));

        params = params.replace('&', '?');
        outputDiv.innerHTML = '';
        outputDiv.appendChild(coordsUl);

        var request = new XMLHttpRequest();
        request.open('GET', params);
        request.send();
    }, function(positionError) {
        document.getElementById('error').innerHTML = error.message;
    }, {
        enableHighAccuracy: true,  // Use the GPS
        timeout: 1000,  // Android was only returning ever 5s, so force lower
        maximumAge: 0  // Never use cached values
    });
}

</script>

</body>
</html>

Add accuracy options for geolocation
Add accuracy options for geolocation
