From 9a4ec62f9239bcb974159a16f1999745917ae85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vicu=C3=B1a?= Date: Tue, 30 Jun 2020 21:30:54 -0400 Subject: [PATCH] Fully implemented GeoLocalization option If the GeoLocalization button is used, the coordinates provided by your browser will be used instead of the manually inserted city name and country to find and show your location's data. Also fixed some error in OpenWeather.js with empty parameters --- index.html | 2 ++ js/GeoPosition.js | 2 ++ js/OpenWeather.js | 10 +++++----- js/main.js | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 3a3d12f..b7eba18 100644 --- a/index.html +++ b/index.html @@ -80,6 +80,8 @@

Simple Weather Overlay

+ + diff --git a/js/GeoPosition.js b/js/GeoPosition.js index d3d3392..fbd8912 100644 --- a/js/GeoPosition.js +++ b/js/GeoPosition.js @@ -4,6 +4,8 @@ function ShowPositionValues(position){ console.log("long: " + pos.longitude); $(".place_field").attr("disabled", true); $("#city_input").val("Using geolocation info"); + $("#lat_field").val(pos.latitude); + $("#lon_field").val(pos.longitude); } function GetPosition(){ diff --git a/js/OpenWeather.js b/js/OpenWeather.js index 693513a..6b051a1 100644 --- a/js/OpenWeather.js +++ b/js/OpenWeather.js @@ -19,7 +19,7 @@ $(document).ready(function(){ $(".WeatherInfo").addClass("Light"); } var place = ""; - if (parameters.get("country") !== "") { + if (parameters.get("country")) { place = parameters.get("city") + "," + parameters.get("country").toLowerCase(); } else { @@ -41,15 +41,15 @@ $(document).ready(function(){ var tempMin; var tempMax; var midday = GetMidday(); - if (parameters.lat != null){ - placeCoordinates.lat = parameters.lat; - placeCoordinates.lon = parameters.lon; + if (parameters.get("lat")){ + placeCoordinates.lat = parameters.get("lat"); + placeCoordinates.lon = parameters.get("lon"); } function PlaceData() { let params = {}; - if (placeCoordinates.lat != null){ + if (placeCoordinates.lat){ params = { "lat": placeCoordinates.lat, "lon": placeCoordinates.lon, diff --git a/js/main.js b/js/main.js index 7cfec4a..f7e9eac 100644 --- a/js/main.js +++ b/js/main.js @@ -9,6 +9,7 @@ $(document).ready( function() { $("#country-list").append($("")); } }); + $.ajax({ url: "https://gist.githubusercontent.com/jvicu2001/666fc491228453a8f1981167bb6c8912/raw/24b3e3155a0b9f398b629c7f907f2cbc52d36766/openweather_languages.json", type: "GET", @@ -19,6 +20,9 @@ $(document).ready( function() { $("#language-list").append($("")); } }); + if ($("#city_input").val() == "Using geolocation info"){ + $("#city_input").val(""); + } } ); function makeURL() { var params = $( "form" ).serialize();