Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup geocoder with google_premier?

I've read the docs for the geocoder gem which state you can set a key, client and channel when using Google Premier.

According to some other posts I've read here, it's now possible to use an API key and still not pay as long as you're below the free threshold. We need to do this as we host with Heroku and we keep hitting our daily limit. We're not ourselves, but without any sort of other identification, we're probably reaching a limit identified by IP shared with other Heroku sites. Using a key will help identify us and therefore keep us from hitting a limit.

However, when I look at the sign up pages for the Google API, there are a baffling array of client ids, api keys and secrets, for installed apps, web apps and so on. Which combination is the one required to make geocoder burst into life?

like image 367
Simmo Avatar asked Feb 21 '13 16:02

Simmo


People also ask

How do I set up geocoding on Google Maps?

In the Cloud Console, open the Google Maps Platform Quotas page. Click the APIs drop-down and select the Geocoding API. To view the quota limits, scroll down to the Requests card.

What is Google Geocoding and how does it work?

Google ¶. Geocoding is the process of converting addresses (like “1600 Amphitheatre Parkway, Mountain View, CA”) into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. Using Geocoder you can retrieve google’s geocoded data from Google Geocoding API.

How do I get an API key for geocoding?

Activate the API and get an API key. To use the Geocoding API, you must first activate the API in the Google Cloud Platform Console and obtain the proper authentication credentials. You need to provide an API key in each request (or a client ID if you have a Premium Plan). Click the button below to flow through a process where you will:

What is Google Geocoder class?

Geocoder class A service for converting between an address and a LatLng. Creates a new instance of a Geocoder that sends geocode requests to Google servers. Geocode a request. google.maps.


2 Answers

To answer the question :

When subscribing to Google Premier, you should have received a client id starting by gme- and a key (see https://developers.google.com/maps/documentation/business/articles/prelaunch_checklist#welcome_letter)

The third argument needed by geocoder is the channel, that can be any kind of string (see https://developers.google.com/maps/documentation/business/guide#Channels )

You need to add the list of authorised urls originating the requests in the Google Portal (see https://developers.google.com/maps/documentation/business/guide#URLs ).

From the Geocoder doc, you can use a setting like :

# -*- encoding : utf-8 -*-
Geocoder.configure do |config|
  config.lookup = :google_premier
  config.api_key = ["gme-client-id","key", "channel"]
  config.timeout = 10
  config.units = :km
end

But it would probably be a better choice to use client-side geocoding like recommended here : https://developers.google.com/maps/articles/geocodestrat?hl=fr#client

like image 170
tal Avatar answered Oct 03 '22 13:10

tal


This worked for me:

Geocoder.configure(
  :lookup => :google_premier,
  :api_key => [ 'GOOGLE_CRYPTO_KEY', 'GOOGLE_CLIENT_ID', 'GOOGLE_CHANNEL' ],
  :timeout => 5,
  :units => :km,
)

You'll need to substitute in the corresponding values from your Google Maps for Business welcome email. Channel is a value of your choosing.

like image 23
chopper Avatar answered Oct 03 '22 11:10

chopper