28
loading...
This website collects cookies to deliver better user experience
CREATE CREDENTIALS
at the top of the page:CLOSE
. For the second key we'll need to add some restrictions as we'll be using this later in a way that will display it in the browser.HTTP referrers (web sites)
as the application restriction and add click ADD AN ITEM
. This input allows us to choose which websites have access to the key - in this case we need to set localhost:3000/*
to give access to our local development environment. If you plan to push this project to a live repository, add the link to the hosted site in here as well.Add a map to your website, providing imagery and local data from the same source as Google Maps. Style the map to suit your needs. Visualize your own data on the map, bring the world to life with Street View, and use services like geocoding and directions.
Convert addresses into geographic coordinates (geocoding), which you can use to place markers or position the map. This API also allows you to convert geographic coordinates into an address (reverse geocoding).
Library
. This will take you to a new page where you can search for the APIs:Maps JavaScript API
and open the top result. On the API page, click ENABLE
. You'll be redirected to an API dashboard that shows which APIs you have enabled. Go back to the library page and repeat the same process for Geocoding API. .env
file, we'll need to do a bit of setting up to make it readable in our development environment. We'll be using the dotenv gem. We only want to use this locally so let's go back to our Gemfile
, find the development and test group, and add the gem there. Replace it with the following:group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'dotenv-rails'
end
Ctrl+C
) and run the Rails gem install command:bundle install
dotenv
available, as well as other technical ways of managing environment variables as showcased in this video. For the sake of simplicity we'll create our own for now but, if you're working on bigger projects or particularly sensitive data then it's worth exploring other options to find the right one for your use case./rails-react-google-maps
) create a new file called .env
(it mustn't have a file extension on the end). .gitignore
- open it up and add the following at the bottom:.env
.env
file to make them accessible throughout our app. Naming conventions for environment variables are as follows:NAME_OF_VARIABLE=value
GMAPS_API_SERVER_KEY=[your_key_here]
GMAPS_API_BROWSER_KEY=[your_key_here]
ENV['GMAPS_API_BROWSER_KEY']