From 3967a15485271a30a747c34a73d6aa128759ee70 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 22 Nov 2019 17:18:20 -0700 Subject: [PATCH] Pre-populate user location with GeoIP data from the server --- www/assets/js/location.js | 17 ++++++++++++++++- www/settings.js | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/www/assets/js/location.js b/www/assets/js/location.js index 018492d..96f72df 100644 --- a/www/assets/js/location.js +++ b/www/assets/js/location.js @@ -20,6 +20,21 @@ if (localStorage.getItem("user_latitude") != null && localStorage.getItem("user_ userPosition.coords.longitude = localStorage.getItem("user_longitude"); } +// Request the user's IP geolocation as a poor substitute for an actual location +// Should improve UX for weather tool at least +$.ajax({ + url: SETTINGS.geoipapi, + dataType: 'json', + timeout: 10 * 1000, + success: function (resp) { + if (resp.status == "OK" && userPosition.coords.accuracy > 99999) { + userPosition.coords.latitude = resp.location.latitude; + userPosition.coords.longitude = resp.location.longitude; + userPosition.coords.accuracy = 99999; + } + } +}); + var geoerrorcount = 0; var mapLocationControlStarted = false; @@ -53,7 +68,7 @@ if ("geolocation" in navigator) { if (packages[i].lastAlert > currentTimestamp - alertinterval) { continue; } - + if (getUndeliveredCount(packages[i]) == 0) { continue; } diff --git a/www/settings.js b/www/settings.js index 89cdb9a..69f1674 100644 --- a/www/settings.js +++ b/www/settings.js @@ -80,5 +80,6 @@ var SETTINGS = { }, geocodeapi: "https://apis.netsyms.net/packagehelper/geocode.php", trackingapi: "https://apis.netsyms.net/packagehelper/track.php", - weatherapi: "https://apis.netsyms.net/packagehelper/weather.php" + weatherapi: "https://apis.netsyms.net/packagehelper/weather.php", + geoipapi: "https://apis.netsyms.net/packagehelper/geoip.php" }