From 4a5ada21c5048ea0c1adfb0625b6340f58e6e25f Mon Sep 17 00:00:00 2001
From: Jakob Stendahl <jakobste@uio.no>
Date: Wed, 14 Oct 2020 14:00:36 +0200
Subject: Add pulling of location

---
 src/components/WeatherCurrent.svelte | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'src/components/WeatherCurrent.svelte')

diff --git a/src/components/WeatherCurrent.svelte b/src/components/WeatherCurrent.svelte
index c5cac3e..7ca6ac4 100644
--- a/src/components/WeatherCurrent.svelte
+++ b/src/components/WeatherCurrent.svelte
@@ -10,7 +10,7 @@
 	let locationSupported;
 	let dataLoading = true;
 
-    let location = "The earth";
+    let location = "-";
     let date = "-";
     let kp_now = "-";
     let kp_min = "-";
@@ -25,6 +25,13 @@
         temp =  yr_data["properties"]["timeseries"][0]["data"]["instant"]["details"]["air_temperature"];
     }
 
+    async function getLocation(longitude, latitude) {
+        console.log(`https://geocode.xyz/${longitude},${latitude}?geoit=json`);
+        let locDat = await fetch(`https://geocode.xyz/${latitude},${longitude}?geoit=json`).then(r => r.json());
+        console.log(locDat);
+        location = locDat["city"];
+    }
+
     async function getUSNOAAData() {
         bz = (await fetch("https://services.swpc.noaa.gov/products/summary/solar-wind-mag-field.json").then(res => res.json()))["Bz"];
         let kp_data = (await fetch('https://services.swpc.noaa.gov/products/noaa-planetary-k-index-forecast.json').then(res => res.json()));
@@ -71,6 +78,7 @@
 		longitude = position.coords.longitude
 		latitude = position.coords.latitude
 		getMETNorData(longitude, latitude)
+        getLocation(longitude, latitude);
 	}
 
 	function locationError(err) {
-- 
cgit v1.2.3

