Search code examples
ruby-on-railsrubygemsrails-geocoder

Set default country in rubys geocoder


I am using this great gem 'geocoder' by alexreisner with nominatim as geolocation service.

Because the service of my web application is only available for a specific country I was wondering, if it is possbile to set a default country or region?

By setting a default country I am hoping to decrease multiple (false) hits.


Solution

  • You can just add a hardcoded Country in your model, such as:

    geocoded_by :address
    
    def address
      [street, city, state, 'Belgium'].compact.join(', ')
    end
    

    Remove/add fields from that array as required.