|
|
|
@ -290,6 +290,28 @@ function addPackageByAddress(number, street, citystate, type, callback) {
|
|
|
|
|
var deadline = false;
|
|
|
|
|
|
|
|
|
|
var ajaxlookup = function () {
|
|
|
|
|
var geocodecache = localStorage.getItem("geocode_cache");
|
|
|
|
|
if (geocodecache == null) {
|
|
|
|
|
geocodecache = "{}";
|
|
|
|
|
localStorage.setItem("geocode_cache", "{}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
geocodecache = JSON.parse(geocodecache);
|
|
|
|
|
var cachekey = number + " || " + street + " || " + citystate;
|
|
|
|
|
var cacheitem = geocodecache[cachekey];
|
|
|
|
|
var timestamp = Math.floor(Date.now() / 1000);
|
|
|
|
|
if (typeof cacheitem != 'undefined') {
|
|
|
|
|
if (cacheitem.added + SETTINGS.geocodecacheexpiry < timestamp) {
|
|
|
|
|
console.log("Info", "Removing expired geocode cache item " + cachekey);
|
|
|
|
|
delete geocodecache[cachekey];
|
|
|
|
|
localStorage.setItem("geocode_cache", JSON.stringify(geocodecache));
|
|
|
|
|
} else {
|
|
|
|
|
console.log("Info", "Using cached geocode result", cacheitem);
|
|
|
|
|
addPackage(cacheitem.address, cacheitem.latitude, cacheitem.longitude, type, callback, deadline);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: SETTINGS.geocodeapi,
|
|
|
|
|
dataType: 'json',
|
|
|
|
@ -308,6 +330,13 @@ function addPackageByAddress(number, street, citystate, type, callback) {
|
|
|
|
|
if (resp.status == "OK") {
|
|
|
|
|
if (resp.accuracy.ok) {
|
|
|
|
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback, deadline);
|
|
|
|
|
geocodecache[cachekey] = {
|
|
|
|
|
address: resp.address.street,
|
|
|
|
|
latitude: resp.coords[0],
|
|
|
|
|
longitude: resp.coords[1],
|
|
|
|
|
added: Math.floor(Date.now() / 1000)
|
|
|
|
|
};
|
|
|
|
|
localStorage.setItem("geocode_cache", JSON.stringify(geocodecache));
|
|
|
|
|
} else {
|
|
|
|
|
playSound("error");
|
|
|
|
|
app.dialog.confirm(
|
|
|
|
|