XavB64 / lowtrip

A web app to compute travel CO2eq for different means of transport worldwide
https://lowtrip.fr
GNU Affero General Public License v3.0
56 stars 6 forks source link

When formatting the city's name, don't use the state if it's undefined #80

Closed quentinms closed 5 months ago

quentinms commented 5 months ago

For example, Lisboa doesn't have a state so it's displayed as "Lisboa, undefined, Portugal".

Before/After

Capture d’écran 2024-06-03 à 10 38 54 Capture d’écran 2024-06-03 à 10 38 36

When searching for "Lisboa" using the API it returns both the city of Lisbon and the district.

{
            "geometry": {
                "coordinates": [
                    -9.1365919,
                    38.7077507
                ],
                "type": "Point"
            },
            "type": "Feature",
            "properties": {
                "osm_type": "N",
                "osm_id": 265958490,
                "country": "Portugal",
                "osm_key": "place",
                "city": "Lisbon",
                "countrycode": "PT",
                "osm_value": "city",
                "postcode": "1100-148",
                "name": "Lisbon",
                "county": "Lisbon",
                "type": "district"
            }
        },
        {
            "geometry": {
                "coordinates": [
                    -9.151827931741947,
                    38.7440523
                ],
                "type": "Point"
            },
            "type": "Feature",
            "properties": {
                "osm_type": "R",
                "osm_id": 5400890,
                "extent": [
                    -9.2298356,
                    38.7967584,
                    -9.0863328,
                    38.6913994
                ],
                "country": "Portugal",
                "osm_key": "place",
                "countrycode": "PT",
                "osm_value": "city",
                "name": "Lisbon",
                "county": "Lisbon",
                "type": "city"
            }
        },

If you would like to display both a separate entries, we could format it as "Lisboa, Portugal (city)" and "Lisboa, Portugal (disctrict)".

It would be more work as the type needs to be piped through and the type needs to be translated, but it might be more resilient to some edge cases I'm not aware of.