frontend: createpost: add reverse location lookup to get city and country

Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
Nicolas Froger 2024-07-25 19:26:40 +02:00
commit ce2b6338c3
No known key found for this signature in database

View file

@ -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)
})
}
</script>
<template>
@ -228,7 +242,7 @@ function mediaReorder(index, diff) {
</FormControl>
</FormItem>
</FormField>
<Button class="place-self-end">
<Button class="place-self-end" @click="getCityAndCountry">
<RefreshCcw />
</Button>
</div>