diff --git a/summer2024-frontend/src/views/CreatePostView.vue b/summer2024-frontend/src/views/CreatePostView.vue index 59c0fe2..dabb974 100644 --- a/summer2024-frontend/src/views/CreatePostView.vue +++ b/summer2024-frontend/src/views/CreatePostView.vue @@ -167,7 +167,18 @@ function getCityAndCountry() { fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=jsonv2`) .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) })