Last Updated: February 25, 2016
·
1.889K
· kenjione

Ruby geocoder settings

In a case to use Google Geocoding API in RoR application we need to define our API key in initializer:

Geocoder.configure(

    # geocoding service:
    :lookup => :google,

    # IP address geocoding service:
    :ip_lookup => :maxmind,

    # to use an API key:
    :api_key => 'AAAAbBBBBcCCCdDDDxXXXyYYYzzZZ11_2233',

    # this is very important option for configuring geocoder with API key
    :use_https => true,

    # geocoding service request timeout, in seconds (default 3):
    :timeout => 3,

    # set default units to kilometers:
    :units => :km,
)

Don't forget to define use_https: true, otherwise u will get an error:

>> Geocoder.search("Moscow")
Google Geocoding API error: request denied.
[]

But if u want to use geocoder without API key, u don't need to define that option.