leaflet-geosearch
leaflet-geosearch copied to clipboard
OpenStreetMapProvider is returning empty result in Geosearch control
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
- https://nominatim.openstreetmap.org/search?format=json&q=Kundana, Devanahalli taluk, Bangalore Rural, Karnataka, India --> THIS RETURNS PROPER RESULTS
Note to self, also see https://github.com/smeijer/leaflet-geosearch/issues/205#issuecomment-543068067
@smeijer any solutions?
Not yet, it has the top priority.
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.
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);