frontend: create-post: fix city name lookup
Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
parent
8977d36a40
commit
9ab5e684f3
1 changed files with 12 additions and 1 deletions
|
|
@ -167,7 +167,18 @@ function getCityAndCountry() {
|
||||||
|
|
||||||
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=jsonv2`)
|
fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=jsonv2`)
|
||||||
.then((resp) => resp.json()).then((resp) => {
|
.then((resp) => resp.json()).then((resp) => {
|
||||||
form.setFieldValue('city', resp.address.village)
|
const cityFieldOrder = ['city', 'town', 'borough', 'village', 'suburb', 'municipality', 'county', 'state']
|
||||||
|
let found = false
|
||||||
|
for (const field of cityFieldOrder) {
|
||||||
|
if (Object.hasOwn(resp.address, field)) {
|
||||||
|
found = true
|
||||||
|
form.setFieldValue('city', resp.address[field])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
form.setFieldValue('city', 'endroit perdu')
|
||||||
|
}
|
||||||
form.setFieldValue('country', resp.address.country)
|
form.setFieldValue('country', resp.address.country)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue