0

I'm using ol.control.SearchNominatim for address search.

However, I would like to limit the search to only one country, state and city.

For example: country = Brazil, state = Sao Paulo, city ​​= Sao Paulo

Is it possible?

var searchNominatim = new ol.control.SearchNominatim (
{   
    reverse: false,
    polygon: false,
    //url: https://nominatim.openstreetmap.org/ui/search.html?city=S%C3%A3o+Paulo&county=Brasil&state=Regi%C3%A3o+Imediata+de+S%C3%A3o+Paulo,
    position: true, // Search, with priority to geo position
    placeholder: "Search",
    target: $("#search > div").get(0)
});
5
  • You would need to specify the viewbox for the city nominatim.org/release-docs/develop/api/Search/… viglino.github.io/ol-ext/doc/doc-pages/… Since that is a rectangle it would not guarantee the result would be inside the city boundary, which is unlikely to be rectangular.
    – Mike
    Aug 28, 2022 at 16:18
  • Thanks for the help, but it didn't work. I tried to write the filters in the url but it didn't work either. url: https://nominatim.openstreetmap.org/ui/search.html?city=S%C3%A3o+Paulo&county=Brasil&state=Regi%C3%A3o+Imediata+de+S%C3%A3o+Paulo
    – user210138
    Aug 29, 2022 at 22:37
  • 1
    You also need to set bounded when you use viewbox. If you first find the city with nominatim you can use the geometry to set the viewbox codesandbox.io/s/simple-forked-tuzse7?file=/main.js
    – Mike
    Aug 30, 2022 at 12:16
  • Mike, thank you. Sorry to write as an answer and not as a comment. But it's been a while and I can't log into the account I asked the question anymore.. Thank you and sorry for the delay in getting back to you. I've tested your code, but it's still not working exactly as I need it. For example, I typed Rua Oratório, and it showed in the select box several streets with the same name and some are not in the city of São Paulo. I would like to filter so that they only show the streets of a certain city. Sep 21, 2022 at 12:04
  • Nominatin with a q= as used by ol-ext query can only filter by a viewbox extent. You would need to override the ol-ext response handler to filter out results inside that extent which do not intersect the city geometry codesandbox.io/s/simple-forked-swyn8w?file=/main.js
    – Mike
    Sep 25, 2022 at 14:50

1 Answer 1

0

use country code and city code:

var requestData = searchNominatim.requestData.bind(searchNominatim);
    searchNominatim.requestData = function(e){
        var data = requestData(e);
        data.countrycodes = 'countrycode,citycode,...';
        return data;
};

you can find your country/city code on google

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.