Last active
April 14, 2016 17:36
-
-
Save marxjohnson/59f3e47fe44eaee6dcaec961c95226c0 to your computer and use it in GitHub Desktop.
Ubuntu podcast latitude script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var map = document.getElementById('map'); | |
var error = document.getElementById('error'); | |
var urlstub = "http://www.openstreetmap.org/export/embed.html?"; | |
function updateMap() { | |
var request = new XMLHttpRequest(); | |
request.open('GET', 'latitudefile.txt', true); | |
request.onload = function() { | |
if (request.status >= 200 && request.status < 400) { | |
// Success! | |
var data = JSON.parse(request.responseText); | |
// Get the co-ordinates | |
var lat = parseFloat(data.data[1][0]); | |
var lon = parseFloat(data.data[2][0]); | |
var scale = 0.05; | |
if (lat == 0 && lon == 0) { | |
// If we don't have a position, default to a map of the whole UK. | |
lat = 54; | |
lon = -0.45; | |
scale = 2; | |
error.style.display = 'block'; | |
} else { | |
error.style.display = 'none'; | |
} | |
// If we do have a postion, calculate the top and bottom of the map. | |
var toplat = lat - scale; | |
var toplon = lon - scale; | |
var bottomlat = lat + scale; | |
var bottomlon = lon + scale; | |
// Create the URL | |
var url = urlstub + "bbox=" + toplon + "," + toplat + "," + bottomlon + "," + bottomlat | |
+ "&layer=mapnik" | |
// Add the marker | |
if (scale == 0.05) { | |
url += "&marker=" + lat + "," + lon; | |
} | |
map.setAttribute('src', url); | |
} | |
}; | |
request.send(); | |
} | |
updateMap(); | |
setInterval(updateMap, 30000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment