diff --git a/package.json b/package.json index 8e700f1..3211221 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pebble-directions", "author": "Dyedgreen", - "version": "1.5.0", + "version": "1.6.0", "keywords": [ "navigation", "maps", diff --git a/src/js/location.js b/src/js/location.js index 4bdc496..a727c06 100644 --- a/src/js/location.js +++ b/src/js/location.js @@ -35,13 +35,20 @@ function makeJsonHttpGetRequest(url, callback, logResponseText) { } // Return the current position to the callback (callback params: success / lat / lon) -function loadCurrentLocation(callback) { +function loadCurrentLocation(callback, retry) { navigator.geolocation.getCurrentPosition( // Success function(pos) { try { //callback(true, 52.5, 13.4); /* THIS IS FOR DEMO / SCREENSHOTS IN THE EMULATOR */ - callback(true, pos.coords.latitude, pos.coords.longitude); + if (pos.coords.accuracy <= 100 || retry !== true) { + // Accuracy is good, use this location OR we should not retry! + callback(true, pos.coords.latitude, pos.coords.longitude); + } else if (retry === true) { + // Try once more + console.log('Will try to reload current location, accuracy:', pos.coords.accuracy); + loadCurrentLocation(callback, false); + } } catch (e) { // No location permission callback(false, 0, 0); @@ -200,7 +207,7 @@ function createRoute(routeType, searchText, callback) { } else { routeErrorCallback(callback); } - }); + }, true); } // Helper function to define createRoute error callback all in one place function routeErrorCallback(callback) {