Search code examples
ruby-on-railsrails-geocoder

Rails geocoder dynamically set language and units


I'm trying to achieve so that the language will be set dynamically before geocoding and/or reverse geocoding occurs, right now, I set the language in an initializer of the app.

Geocoder.configure(

    :units => :km,
    :language => :en
)

I would like it so that the language would be set dynamically, for example:

Geocoder.configure(

    :units => :km,
    :language => lambda {|something| I18n.locale}
)

does anyone knows how this can be achieved?


Solution

  • looking at the code it seems like this is not possible.

    what you can do though, is re-configure on every call to google

    Geocoder.configure(language: :en)
    Geocoder.search("Nantes, France")
    

    this kind of sucks. i think the api should allow you to pass that in as a parameter like :unit.

    i created a pull-request for this feature https://github.com/alexreisner/geocoder/pull/654

    UPDATE

    so it actually is possible:

    Geocoder.search("Nantes, France", params: {language: :fr})
    

    plus there is another change incoming that supporting this https://github.com/alexreisner/geocoder/pull/655