I'm tasked with creating a small app prototype for a school assignment that interacts with the Forecast.io API. While I don't have much experience working with APIs, the code seems clean and functional.
However, within Brackets, JSHint is flagging "Navigator not defined (W117)". Additionally, console.log statements are not functioning in certain functions, and the browser isn't prompting me to share my location. Even after copying the exact code, the same issues persist.
None of the console logs in the file are returning any data, making it impossible for me to verify if my browser is receiving location information.
//Declare JSON
(function () {
'use strict';
/*global $, jQuery, console, alert*/
//Define Variables
var latitude, longitude, url, App, myApp, day, days, month, months, year, years, dateTime, getTest, date, Location, myLocation;
App = function () {
this.getLocation = function () {
if (navigator.geolocation) {
console.log("Geofix works");
navigator.geolocation.getCurrentPosition(this.updateWeather);
} else {
alert("Geolocation fix failed");
}
};
this.updateWeather = function (posn) {
console.log("Position OK");
latitude = posn.coords.latitude;
longitude = posn.coords.longitude;
console.log(latitude);
console.log(longitude);
url = "https://api.forecast.io/forecast/412e0bc4cc3095a2de7d0bdf663f4e3e/" + latitude + ',' + longitude + "?units=si";
$.ajax({
url: url,
dataType: 'jsonp',
type: 'GET',
success: function (resp) {
console.log(resp);
date = new Date();
getTest = date.getDate();
day = date.getDay();
month = date.getMonth();
year = date.getFullYear();
//Insert arrays
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
}
});
};
};
myLocation = new App();
myLocation.getCurrentLocation();
}());