Adjust location code for better experience

master
Skylar Ittner 8 years ago
parent f143303217
commit 3e76b407e7

@ -127,15 +127,6 @@ function mapPos(lat, lon) {
if (fetchplacecounter > 10) { if (fetchplacecounter > 10) {
fetchplacecounter = 0; fetchplacecounter = 0;
} }
//map.setView(new L.LatLng(lat, lon), 16, {animate: true});
//map.panTo(new L.LatLng(lat, lon));
//map.invalidateSize();
//redraw('.leaflet-map-pane');
// $('.leaflet-map-plane').css('height', '90%');
// setTimeout(function () {
// $('#map').css('width', '100%');
// $('#map').css('height', '100%');
// }, 100);
} }
function onPlaceTap(feature, layer) { function onPlaceTap(feature, layer) {
@ -145,6 +136,9 @@ function onPlaceTap(feature, layer) {
} }
function loadPlaces(lat, long) { function loadPlaces(lat, long) {
if (!lockGot) {
return;
}
var url = mkApiUrl('places', 'gs') + "?lat=" + lat + "&long=" + long + "&radius=.5&names=1"; var url = mkApiUrl('places', 'gs') + "?lat=" + lat + "&long=" + long + "&radius=.5&names=1";
try { try {
$.getJSON( $.getJSON(
@ -214,8 +208,16 @@ function pingServer() {
} }
} }
var errorMsgShown = false;
function onError(error) { function onError(error) {
$('#loading-error').text("Check your device's network and location settings, and ensure a clear view of the sky."); if (!errorMsgShown) {
var msg = error.message;
if (msg.toLowerCase().includes("timeout")) {
msg = "no lock within 15 seconds";
}
$('#loading-error').text("Check your device's network and location settings, and ensure a clear view of the sky (" + msg + ").");
errorMsgShown = true;
}
} }
function popDiagData() { function popDiagData() {
@ -229,10 +231,10 @@ function popDiagData() {
"Close"); "Close");
} }
// Initial GPS position and stuff // Initial GPS position and stuff
navigator.geolocation.getCurrentPosition(updatePosition, onError, {timeout: 10000, enableHighAccuracy: true}); navigator.geolocation.getCurrentPosition(updatePosition, onError, {timeout: 15000, enableHighAccuracy: true});
// Update position // Update position
setInterval(function () { setInterval(function () {
navigator.geolocation.getCurrentPosition(updatePosition, onError, {timeout: 10000, enableHighAccuracy: true}); navigator.geolocation.getCurrentPosition(updatePosition, onError, {timeout: 1000, enableHighAccuracy: true});
}, 1000); }, 1000);
// Update places // Update places
setInterval(function () { setInterval(function () {
@ -246,10 +248,5 @@ setTimeout(function () {
}, 15 * 1000); }, 15 * 1000);
setTimeout(function () { setTimeout(function () {
// GPS lock is taking too long, let's GTFO of the loading screen $('#loading-error').text("If you're outside and the settings are OK, something has gone wrong. Try restarting or reinstalling the app.");
$('#loading').fadeOut('slow', function () { }, 45 * 1000);
$('#no-lock').css('display', 'block');
$('#loading').css('display', 'none');
updateStatusBarColor();
});
}, 30 * 1000);