Skip to content

Commit

Permalink
Fully implemented GeoLocalization option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jvicu2001 committed Jul 1, 2020
1 parent 332ff5c commit 9a4ec62
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ <h1 class="display-2">Simple Weather Overlay</h1>
<input type="checkbox" class="custom-control-input" id="min-max_text" name="min-max_text">
<label class="custom-control-label" for="min-max_text">Show Min/Max text?</label>
</div>
<input type="hidden" id="lat_field" name="lat" value="">
<input type="hidden" id="lon_field" name="lon" value="">


</form>
Expand Down
2 changes: 2 additions & 0 deletions js/GeoPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
10 changes: 5 additions & 5 deletions js/OpenWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $(document).ready( function() {
$("#country-list").append($("<option value=" + country + ">" + json[country] + "</option>"));
}
});

$.ajax({
url: "https://gist.githubusercontent.com/jvicu2001/666fc491228453a8f1981167bb6c8912/raw/24b3e3155a0b9f398b629c7f907f2cbc52d36766/openweather_languages.json",
type: "GET",
Expand All @@ -19,6 +20,9 @@ $(document).ready( function() {
$("#language-list").append($("<option value=" + language + ">" + json[language] + "</option>"));
}
});
if ($("#city_input").val() == "Using geolocation info"){
$("#city_input").val("");
}
} );
function makeURL() {
var params = $( "form" ).serialize();
Expand Down

0 comments on commit 9a4ec62

Please sign in to comment.