Search code examples
ruby-on-railsrubytimezonegeocode

How to get Timezone with geocode gem?


I have to add a time_zone_select into my Rails application. I was considering some gems to put a default value based on the user request, but I've seen that the project has already installed geocode gem for this purpose.

Is there any way of get the timezone through this gem?


Solution

  • You cannot get timezone directly from geocoder gem. It can just give you location.

    You can use the gem below to get the timezone for a particular zone or for (lat,long) values.

    https://github.com/panthomakos/timezone

    timezone = Timezone::Zone.new :latlon => [-34.92771808058, 138.477041423321]
    timezone.zone
    => "Australia/Adelaide"
    timezone.time Time.now
    => 2011-02-12 12:02:13 UTC