Trying to be more robust to find the name of a locality with nominatim...

This commit is contained in:
Eric van der Vlist 2023-01-05 23:02:40 +01:00
parent 97f11239e8
commit 040c0271d7
1 changed files with 16 additions and 6 deletions

View File

@ -26,11 +26,21 @@ export const findAddress = memoize(_findAddress, {
});
export const getVillageOrTown = (address: any) => {
if (address?.address?.village) {
return address.address.village;
const citySynonyms = [
'village',
'city',
'town',
'municipality',
'hamlet',
'suburb',
'locality',
];
for (let synonym of citySynonyms) {
console.log({ caller: 'getVillageOrTown', address, synonym });
if (synonym in address?.address) {
return address?.address[synonym];
}
}
if (address?.address?.city) {
return address.address.city;
}
return address?.address?.town;
return address?.address?.country;
};