leaflet-control-geocoder icon indicating copy to clipboard operation
leaflet-control-geocoder copied to clipboard

No results are returned when using `format: "geocodejson"`

Open kendlbat opened this issue 11 months ago • 1 comments

We would like to use the following geocoder:

var nominatim = L.Control.Geocoder.nominatim({
    reverseQueryParams: {
        format: "geocodejson",
        addressdetails: 1,
        "accept-language": "de-AT,de-DE",
    },
    geocodingQueryParams: {
        countrycodes: "at",
        "accept-language": "de-AT,de-DE",
    },
});

But when doing a reverse geocode lookup, an empty array is returned due to the following if-statement (this is minified JS so not very helpful): image

The chain of failures is the following:

  • NominatimResult (defined here) is incorrect and does not account for different format flags being used, which further leads to incorrect expectations about the data returned by Nominatim.
  • reverse (defined here) incorrectly assumes that lat and lon are present in the returned data and returns an empty array instead of a) useful error information or b) data.

image

My suggestions are:

  • Correct this behaviour and return the expected result in the "geocodejson"-format. (Recommended)
  • Document this incorrect and unexpected behaviour and alter the L.Control.Geocoder.nominatim options to respond with an error when trying to pass the "geocodejson" format.

Update: The response from nominatim when using the "geocodejson"-format looks like the following: image

kendlbat avatar Jan 02 '25 14:01 kendlbat

Hi,

yeah, the error handling should be improved overall in leaflet-control-geocoder.

Nominatim support a bunch of different output formats, see https://nominatim.org/release-docs/latest/api/Output/. Currently, only the default JSON is supported. Being curios, why are you overriding the format to GeocodeJSON?

Would you like to work on some pull requests?

Cheers from Tyrol! 🇦🇹

simon04 avatar Jan 02 '25 17:01 simon04