Skip to content

Commit

Permalink
Initial GeoPosition implementation
Browse files Browse the repository at this point in the history
Just added the button and a function that prints on console the coordinates when pressing the button mentioned before, alongside an initial catch for the new input on OpenWeather.js first request data
  • Loading branch information
jvicu2001 committed Jul 1, 2020
1 parent 62f2407 commit 332ff5c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
4 changes: 4 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
#why-next-min-info {
color: #007bff;
cursor: pointer;
}

.hover-pointer {
cursor: pointer;
}
12 changes: 10 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ <h1 class="display-2">Simple Weather Overlay</h1>
<div class="row">
<div class="input-group mb-3 col-lg-12 col-xl-6">
<div class="input-group-prepend"><span class="input-group-text">City</span></div>
<input type="text" class="form-control" name="city" required>
<input type="text" class="form-control place_field" id="city_input" name="city" required>
<div class="input-group-append hover-pointer" onclick="GetPosition()">
<span class="input-group-text">
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-geo-alt" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10zm0-7a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"></path>
</svg>
</span>
</div>
</div>
<div class="input-group mb-3 col-lg-12 col-xl-6">
<div class="input-group-prepend"><span class="input-group-text">Country</span></div>
<select name="country" class="custom-select" id="country-list">
<select name="country" class="custom-select place_field" id="country-list">
<option value="" selected>Choose a Country</option>
</select>
</div>
Expand Down Expand Up @@ -150,5 +157,6 @@ <h5 class="modal-title">Why shoud I use the next day's minimum temperature?</h5>
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script src="js/main.js"></script>
<script src="js/GeoPosition.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions js/GeoPosition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function ShowPositionValues(position){
let pos = position.coords;
console.log("lat: " + pos.latitude);
console.log("long: " + pos.longitude);
$(".place_field").attr("disabled", true);
$("#city_input").val("Using geolocation info");
}

function GetPosition(){
navigator.geolocation.getCurrentPosition(ShowPositionValues);
}
23 changes: 19 additions & 4 deletions js/OpenWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,32 @@ $(document).ready(function(){
var tempMin;
var tempMax;
var midday = GetMidday();
if (parameters.lat != null){
placeCoordinates.lat = parameters.lat;
placeCoordinates.lon = parameters.lon;
}


function PlaceData() {
$.ajax({
url: "https://api.openweathermap.org/data/2.5/weather",
data: {
let params = {};
if (placeCoordinates.lat != null){
params = {
"lat": placeCoordinates.lat,
"lon": placeCoordinates.lon,
"appid": API_key
}
}
else{
params = {
"q": place,
"APPID": API_key,
"units": units,
"lang": lang
},
}
}
$.ajax({
url: "https://api.openweathermap.org/data/2.5/weather",
data: params,
type: "GET",
dataType: "json"
})
Expand Down

0 comments on commit 332ff5c

Please sign in to comment.