Prioritize city matches against province matches in Nominatim

72 Views Asked by At

I installed Nominatim in combination with the Maplibre geocoder, but I am having troubles getting the results in the correct order of relevance or getting the correct one at all. In Italy many provinces have the same name as the capital of the province, for example Cagliari is both the name of the Province and the name of a city. When I search for

Via Roma, Cagliari

I an expecting to see the result for the street "Via Roma" located in the city of Cagliari, but I get results for "Via Roma" in other cities located in the province of Cagliari instead. This happens frequently with street names that are fairly common across cities in the same area. How can I make Nominatim to give precedence to the street located in the city with the same name or to not take the province into account at all when elaborating the query?

This is how I am calling the geocoder api

var geocoder_api = {
  forwardGeocode: async (config) => {
    const features = [];
    try {
      geocoder_bbox = map.getBounds().toArray().flat()
      let request =
      'https://my.server/search?q=' +
      config.query +
      '&format=geojson&addressdetails=1&viewbox='+geocoder_bbox;
      const response = await fetch(request);
      const geojson = await response.json();
      for (let feature of geojson.features) {
        let center = [
          feature.bbox[0] +
          (feature.bbox[2] - feature.bbox[0]) / 2,
          feature.bbox[1] +
          (feature.bbox[3] - feature.bbox[1]) / 2
        ];
        
          let point = {
            type: 'Feature',
            geometry: {
              type: 'Point',
              coordinates: center
            },
            place_name: feature.properties.display_name,
            properties: feature.properties,
            text: feature.properties.display_name,
            place_type: ['place'],
            center: center
          };
          features.push(point);
        }
      
    } catch (e) {
      console.error(`Failed to forwardGeocode with error: ${e}`);
    }

    return {
      features: features
    };
  }
};
0

There are 0 best solutions below