Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Geocoder gem work with google API key?

I am using ruby geocoder gem for my project and as the project is growing I am starting to look into connecting to the Google API key. After adding this to the project:

Geocoder.configure do |config|

# geocoding service (see below for supported options):
config.lookup = :google

# to use an API key:
config.api_key = 'my_key'

# geocoding service request timeout, in seconds (default 3):
config.timeout = 5

end 

I get Google Geocoding API error: request denied. when I start the application. From reading around, it seems like others switch over to yahoo if they choose to continue using the gem. Can I configure the gem to work with google api key? Mainly, I would like to keep an eye out for the amount of daily queries to avoid going over the limit.

like image 809
user527662 Avatar asked Jul 31 '12 23:07

user527662


People also ask

How can I check if my Google API key is valid?

Go to the Credentials section, which can be accessed from the left side bar under Google Maps Platform > Credentials. Check that the API key you currently use on your website is listed. If that's not the case, switch to a different project, and check the credentials there.

How do I use Google API for geocoding?

Enable Geocoding API In your Google Cloud Platform Console, go to APIs & Services → Dashboard → Enable APIs & Services at the top and choose Maps JavaScript API from the API Library. This will open up the Maps JavaScript API page and Enable it.

Is geocoding API free Google?

The Geocoding API uses a pay-as-you-go pricing model. Geocoding API requests generate calls to one of two SKUs depending on the type of request: basic or advanced.


4 Answers

Geocoder supports Google api keys for Google Premier accounts only.

Its found here in the readme on github: https://github.com/alexreisner/geocoder#google-google-google_premier

If you have a Google Premier api key you just need to put this in an intializer:

# config/initializers/geocoder.rb
   Geocoder.configure(:lookup => :google_premier, :api_key => "...")

And your Geocoder will use your premier key.

like image 64
Mike Heijmans Avatar answered Oct 20 '22 04:10

Mike Heijmans


I had this issue today and managed to solve it by setting use_https e.g.

Geocoder.configure(
  timeout: 15,
  api_key: "YOUR_KEY",
  use_https: true
)
like image 27
DMH Avatar answered Oct 20 '22 02:10

DMH


create a file: config/initializers/geocoder.rb and setup like this:

Geocoder.configure(
  lookup: :google_premier,
  api_key: ['api_key', 'client_id', 'client_id_type'],
)
like image 37
territorial Avatar answered Oct 20 '22 03:10

territorial


Geocoder works fine with the free tier of their Map API. However, to make it work I had to register a key using this page specifically.

https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE


And set up the configuration

# config/initializers/geocoder.rb
Geocoder.configure(
  api_key: 'KEY_HERE',
  use_https: true
)
like image 30
Sergio Tapia Avatar answered Oct 20 '22 04:10

Sergio Tapia