smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.04k stars 273 forks source link

OpenStreetMapProvider is returning empty result in Geosearch control #180

Open jaisuthan opened 5 years ago

jaisuthan commented 5 years ago

We are using the latest version of "leaflet-geosearch" in our application using the OpenStreetMapProvider. Occasionally we observe that clicking on some of the auto-complete search results in geo-search control for some locations returns empty json.

Ex. Following were the search results for keyword "kundan" in the location .1 https://nominatim.openstreetmap.org/search?format=json&q=Kundana Devanahalli, Kundana, Devanahalli taluk, Bangalore Rural, Karnataka, 561203, India --> THIS RETURN EMPTY JSON

  1. https://nominatim.openstreetmap.org/search?format=json&q=Kundana, Devanahalli taluk, Bangalore Rural, Karnataka, India --> THIS RETURNS PROPER RESULTS
location-searchissue
smeijer commented 4 years ago

Note to self, also see https://github.com/smeijer/leaflet-geosearch/issues/205#issuecomment-543068067

Andrew3005 commented 4 years ago

@smeijer any solutions?

smeijer commented 4 years ago

Not yet, it has the top priority.

cirdanmiriel commented 2 years ago

Hi! I am facing the same problem, and just wanted to know why the search is based on the display_name rather that on the osmId and osmType? It would solve this problem and bring a few more info in a single search. For example: https://nominatim.openstreetmap.org/reverse?format=json&osm_type=${osmType}&osm_id=${osmId}

It would be possible to do this since the autocomplete already retrieves the osmType and osmId.

cirdanmiriel commented 2 years ago

Typically, hacking it a bit like this makes it working :


const osmProvider = new OpenStreetMapProvider();
const searchControl = new (SearchControl as any)({
  provider: osmProvider
});

searchControl.onSubmit = (query: any) => {
      fetch(`https://nominatim.openstreetmap.org/reverse?format=json&osm_type=${<string>query.data.raw.osm_type[0].toUpperCase()}&osm_id=${<string>query.data.raw.osm_id}`)
        .then(res => res.json())
        .then(json => osmProvider.parse({data: json}))
        .then((results: any) => {
          if (results && results.length > 0) {
            searchControl.showResult(results[0], query);
          }
        });
    }

this.leafletMap.addControl(searchControl);