Merge pull request #1 from SwiddisZwei/weather
Make weather tracking optional
This commit is contained in:
commit
da64115dbb
@ -24,14 +24,26 @@ const key = `${CONFIG.weatherKey}`;
|
|||||||
setPosition();
|
setPosition();
|
||||||
|
|
||||||
function setPosition(position) {
|
function setPosition(position) {
|
||||||
getWeather();
|
if (!CONFIG.trackLocation || !navigator.geolocation) {
|
||||||
|
if (CONFIG.trackLocation) {
|
||||||
|
console.error('Geolocation not available');
|
||||||
|
}
|
||||||
|
getWeather(CONFIG.defaultLatitude, CONFIG.defaultLongitude);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(pos) => {
|
||||||
|
getWeather(pos.coords.latitude.toFixed(3), pos.coords.longitude.toFixed(3));
|
||||||
|
}, (err) => {
|
||||||
|
console.error(err);
|
||||||
|
getWeather(CONFIG.defaultLatitude, CONFIG.defaultLongitude);
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Weather data
|
// Get the Weather data
|
||||||
function getWeather() {
|
function getWeather(latitude, longitude) {
|
||||||
if(navigator.geolocation) {
|
let api = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${key}`;
|
||||||
navigator.geolocation.getCurrentPosition(function(a) {
|
|
||||||
let api = `https://api.openweathermap.org/data/2.5/weather?lat=${a.coords["latitude"]}&lon=${a.coords["longitude"]}&appid=${key}`;
|
|
||||||
|
|
||||||
console.log(api);
|
console.log(api);
|
||||||
|
|
||||||
@ -50,8 +62,6 @@ function getWeather() {
|
|||||||
.then(function () {
|
.then(function () {
|
||||||
displayWeather();
|
displayWeather();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display Weather info
|
// Display Weather info
|
||||||
|
@ -26,8 +26,9 @@ const CONFIG = {
|
|||||||
weatherKey: 'InsertYourAPIKeyHere123456',
|
weatherKey: 'InsertYourAPIKeyHere123456',
|
||||||
weatherIcons: 'OneDark', // 'Nord', 'Dark', 'White'
|
weatherIcons: 'OneDark', // 'Nord', 'Dark', 'White'
|
||||||
weatherUnit: 'C',
|
weatherUnit: 'C',
|
||||||
weatherLatitude: '37.774929',
|
trackLocation: false, // If false or an error occurs, the app will use the lat/lon below
|
||||||
weatherLongitude: '-122.419418',
|
defaultLatitude: '37.775',
|
||||||
|
defaultLongitude: '-122.419',
|
||||||
|
|
||||||
// ┌─┐┌─┐┬─┐┌┬┐┌─┐
|
// ┌─┐┌─┐┬─┐┌┬┐┌─┐
|
||||||
// │ ├─┤├┬┘ ││└─┐
|
// │ ├─┤├┬┘ ││└─┐
|
||||||
|
Loading…
x
Reference in New Issue
Block a user