From ce2b6338c30ba37e010baa47c06bd379ec9d4747 Mon Sep 17 00:00:00 2001 From: Nicolas Froger Date: Thu, 25 Jul 2024 19:26:40 +0200 Subject: [PATCH] frontend: createpost: add reverse location lookup to get city and country Signed-off-by: Nicolas Froger --- summer2024-frontend/src/views/CreatePostView.vue | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/summer2024-frontend/src/views/CreatePostView.vue b/summer2024-frontend/src/views/CreatePostView.vue index 2a041f5..b731358 100644 --- a/summer2024-frontend/src/views/CreatePostView.vue +++ b/summer2024-frontend/src/views/CreatePostView.vue @@ -159,6 +159,20 @@ function mediaReorder(index, diff) { selectedFiles.value[index + diff] = tmp } +function getCityAndCountry() { + const lat = latitudeInput.value.value + const lon = longitudeInput.value.value + if (!lat || !lon) + return + + fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=jsonv2`) + .then((resp) => resp.json()).then((resp) => { + form.setFieldValue('city', resp.address.village) + form.setFieldValue('country', resp.address.country) + }) + +} +