This commit is contained in:
Kevin Kub 2020-10-18 15:58:14 +02:00 committed by GitHub
parent f9d03d2d19
commit d25eaa9334

View File

@ -8,9 +8,23 @@ Script.setWidget(widget)
Script.complete()
async function createWidget(items) {
Location.setAccuracyToThreeKilometers()
const location = await Location.current()
let location
if(args.widgetParameter) {
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat)
location = {
latitude: fixedCoordinates[0],
longitude: fixedCoordinates[1]
}
} else {
Location.setAccuracyToThreeKilometers()
location = await Location.current()
}
const data = await new Request(apiUrl(location)).loadJSON()
if(!data || !data.features || !data.features.length) {
const errorList = new ListWidget()
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.")
return errorList
}
const attr = data.features[0].attributes
const incidence = attr.cases7_per_100k.toFixed(1)
const cityName = attr.GEN