diff --git a/incidence.js b/incidence.js index fe0463c..cc35544 100644 --- a/incidence.js +++ b/incidence.js @@ -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