Skip to content

Instantly share code, notes, and snippets.

@mchristie
Created August 21, 2013 14:03
Show Gist options
  • Save mchristie/6294868 to your computer and use it in GitHub Desktop.
Save mchristie/6294868 to your computer and use it in GitHub Desktop.
function timeout_warning()
{
$('#location_feedback').html('<p>Hmmm, this is taking a while, maybe your browser doesn\'t support geolocation?<br /><br /><a href="/browse" class="button">Browse towns</a> &nbsp; <a href="/" class="button">Search</a></p>');
$('#location_feedback').attr('class', 'warning');
}
var timer = setTimeout("timeout_warning()", 10000);
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
if (position.coords.accuracy > 25000) {
$('#location_feedback').html('<p>We can\'t get a very accurate fix on your location, sorry.<br />Try <a href="/browse">browsing towns instead</a>.');
$('#location_feedback').html('<br /><a href="/browse" class="button medium">browsing towns</a>.</p>');
$('#radar').remove();
<!-- $('#location_feedback').addClass('alert-box alert'); -->
clearTimeout(timer);
} else {
$('#location_feedback').text('Hazzah! Your location is '+position.coords.latitude+","+position.coords.longitude+', finding takeaways...');
<!-- $('#location_feedback').addClass('alert-box success'); -->
window.location = '/takeaways/near-me/'+position.coords.latitude+"/"+position.coords.longitude;
}
});
} else {
$('#location_feedback').text('Sorry, but geolocation services are not supported by your browser.');
$('#location_feedback').attr('class', 'error');
clearTimeout(timer);
}
// Find a town link just incase
$.getJSON('/browse/town_link', function(data) {
$('#town_link').
html('It looks like your in <strong>'+data.name+'</strong>, would you like to <a href="'+data.url+'">look for Takeaways in '+data.name+'</a>?').
show();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment