Location fix timestamp and logic
This commit is contained in:
parent
18b08bf647
commit
152272c51a
2 changed files with 11 additions and 2 deletions
|
|
@ -35,7 +35,7 @@ Singleton {
|
||||||
|
|
||||||
property string latitude: ""
|
property string latitude: ""
|
||||||
property string longitude: ""
|
property string longitude: ""
|
||||||
property string weatherLastFetch: ""
|
property int weatherLastFetch: 0
|
||||||
property var weather: null
|
property var weather: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +53,14 @@ Singleton {
|
||||||
function init() {// does nothing but ensure the singleton is created
|
function init() {// does nothing but ensure the singleton is created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------
|
||||||
|
function resetWeather() {
|
||||||
|
data.latitude = ""
|
||||||
|
data.longitude = ""
|
||||||
|
data.weatherLastFetch = 0
|
||||||
|
data.weather = null
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
function updateWeather() {
|
function updateWeather() {
|
||||||
if ((data.weatherLastFetch === "") || (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
|
if ((data.weatherLastFetch === "") || (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
|
||||||
|
|
@ -107,6 +115,7 @@ Singleton {
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
function _fetchWeather(latitude, longitude, errorCallback) {
|
function _fetchWeather(latitude, longitude, errorCallback) {
|
||||||
|
console.log("Getting weather")
|
||||||
var url = "https://api.open-meteo.com/v1/forecast?latitude=" + latitude + "&longitude=" + longitude
|
var url = "https://api.open-meteo.com/v1/forecast?latitude=" + latitude + "&longitude=" + longitude
|
||||||
+ "¤t_weather=true¤t=relativehumidity_2m,surface_pressure&daily=temperature_2m_max,temperature_2m_min,weathercode&timezone=auto"
|
+ "¤t_weather=true¤t=relativehumidity_2m,surface_pressure&daily=temperature_2m_max,temperature_2m_min,weathercode&timezone=auto"
|
||||||
var xhr = new XMLHttpRequest()
|
var xhr = new XMLHttpRequest()
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ Singleton {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a Unix Timestamp (in seconds)
|
// Returns a Unix Timestamp (in seconds)
|
||||||
readonly property string timestamp: {
|
readonly property int timestamp: {
|
||||||
return Math.floor(Date.now() / 1000)
|
return Math.floor(Date.now() / 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue