· 6 years ago · Feb 07, 2019, 04:10 AM
1// Author : Sai Satwik Reddy Meda
2// For CS275 - David Augenblick
3function Forecast(){
4 if(navigator.geolocation)
5 {navigator.geolocation.getCurrentPosition(function(position)
6 { var lat = position.coords.latitude;
7 var lon = position.coords.longitude;// Location of User
8 let Client_Id = document.getElementById('ClientID').value // Taking the input data from the user
9 let Secret_Key = document.getElementById('Secretkey').value
10
11
12
13 let URL = "https://api.aerisapi.com/forecasts/"+lat+","+lon+"?client_id="+Client_Id+"&client_secret="+Secret_Key; //URL for the API
14 $.ajaxPrefilter(function( options, original_Options, jqXHR ) {
15 options.async = true;
16 });
17 $.ajax({
18 type: "GET",
19 url: URL,
20 contentType: "application/json; charset=utf-8",
21 data: "{}",
22 async: false,
23 dataType: "json",
24
25 success: function(msg){ //If it's succesful it goes through every element from the JSON objects and adds it to the existing table
26 var trHTML = '';
27
28
29 $.each(msg.response[0].periods, function (i, item) {
30 trHTML += '<tr><td>' + item.validTime.substring(0,10) + '</td><td>' + item.maxTempF + '</td><td>' + item.minTempF + '</td></tr>';
31
32 $('#records_table').append(trHTML);
33 });
34 },
35 error: function(xhr, ajaxOptions, thrownError){
36 $("#current").html("Error fetching" + URL); //For the ERRORS
37 document.getElementById("Out").innerHTML = "Invalid input. Please try again";
38 }
39 });
40}
41)}
42}