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.
Written by Alex Chernyshev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#