1

I want to use the Time zone gem to convert lat and long to a time zone;

  1. I have added the gem in to my file
  2. I have created timezone.rb in config/initializers
  3. I enabled the Google Maps Time Zone API, and added a server key

timezone.rb file:

Timezone::Lookup.config(:google) do |c|
  c.api_key = 'server_key'
end

When I type to rails console;

> timezone = Timezone['America/Los_Angeles']
 => #<Timezone::Zone name: "America/Los_Angeles"> 

This works but when I try to use lat and long google gives connection error;

> timezone = Timezone.lookup(-34.92771808058, 138.477041423321)
Timezone::Error::Google: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Shalafister's
  • 761
  • 1
  • 7
  • 34

1 Answers1

1

Try to check this Github, it will explain everything to you about Google Time Zone API using ruby.

Just make sure you follow this steps:

  1. Ensure you have a Google API Key, server key

  2. Enable the Google Maps Time Zone API

  3. Configure your lookup. NOTE: in Rails it is recommended that you add this code to an initializer

.

Timezone::Lookup.config(:google) do |c|
  c.api_key = 'your_google_api_key_goes_here'
  c.client_id = 'your_google_client_id' # if using 'Google for Work'
end

For more information, you can also check this thread and SO question.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31