Use last known location before GPS warms up (close #19)
This commit is contained in:
parent
afb607a618
commit
385f0ae535
@ -14,6 +14,12 @@ var userPosition = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Preload last known location while GPS warms up
|
||||||
|
if (localStorage.getItem("user_latitude") != null && localStorage.getItem("user_longitude") != null) {
|
||||||
|
userPosition.coords.latitude = localStorage.getItem("user_latitude");
|
||||||
|
userPosition.coords.longitude = localStorage.getItem("user_longitude");
|
||||||
|
}
|
||||||
|
|
||||||
var geoerrorcount = 0;
|
var geoerrorcount = 0;
|
||||||
|
|
||||||
var mapLocationControlStarted = false;
|
var mapLocationControlStarted = false;
|
||||||
@ -21,6 +27,8 @@ var mapLocationControlStarted = false;
|
|||||||
if ("geolocation" in navigator) {
|
if ("geolocation" in navigator) {
|
||||||
navigator.geolocation.watchPosition(function (position) {
|
navigator.geolocation.watchPosition(function (position) {
|
||||||
userPosition = position;
|
userPosition = position;
|
||||||
|
localStorage.setItem("user_latitude", userPosition.coords.latitude);
|
||||||
|
localStorage.setItem("user_longitude", userPosition.coords.longitude);
|
||||||
if (mapLocationControlStarted) {
|
if (mapLocationControlStarted) {
|
||||||
//setMapLocation(position.coords.latitude, position.coords.longitude);
|
//setMapLocation(position.coords.latitude, position.coords.longitude);
|
||||||
// Don't refresh at an interval less than ten seconds
|
// Don't refresh at an interval less than ten seconds
|
||||||
@ -160,14 +168,14 @@ function getDisplayDistance(meters, space) {
|
|||||||
space = true;
|
space = true;
|
||||||
}
|
}
|
||||||
var units = localStorage.getItem("units");
|
var units = localStorage.getItem("units");
|
||||||
|
|
||||||
if (units == null) {
|
if (units == null) {
|
||||||
units = "metric";
|
units = "metric";
|
||||||
}
|
}
|
||||||
|
|
||||||
var number = Math.round(meters);
|
var number = Math.round(meters);
|
||||||
var label = "m";
|
var label = "m";
|
||||||
|
|
||||||
if (units == "imperial") {
|
if (units == "imperial") {
|
||||||
// Convert to feet
|
// Convert to feet
|
||||||
number = Math.round(number * 3.28084);
|
number = Math.round(number * 3.28084);
|
||||||
@ -192,7 +200,7 @@ function getDisplayDistance(meters, space) {
|
|||||||
label = "km";
|
label = "km";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (space) {
|
if (space) {
|
||||||
return number + " " + label;
|
return number + " " + label;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user