Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 570
Itai Sagi Avatar asked Dec 17 '25 11:12

Itai Sagi


1 Answers

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

like image 116
phoet Avatar answered Dec 19 '25 07:12

phoet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!