You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8 KiB

{% extends 'base.html' %}
{% block app_content %}
<meta name="csrf-token" content="{{ csrf_token() }}">
{% block player_app_content %}{% endblock %}
{% endblock %}
{% block scripts %}
{{ super() }}
<script>
4 years ago
$(document).ready(sendLocation)
function sendLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(postCoordinates, showError);
} else {
console.log('Geolocation is not supported by this browser.')
}
4 years ago
}
4 years ago
setInterval(function() {sendLocation()}, 65 * 1000);
4 years ago
function postCoordinates(position) {
$.ajax({
type: "POST",
url: "{{ url_for('main.send_location', username=current_user.name) }}",
data:{
lat: position.coords.latitude,
long: position.coords.longitude
},
error: function(error) {
console.log(error);
}
});
}
4 years ago
var csrftoken = $('meta[name=csrf-token]').attr('content')
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken)
}
}
})
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.")
alert("Please refresh page and allow location sharing, otherwise the game won't work :'(")
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.")
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.")
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.")
break;
}
}
</script>
{% endblock %}