-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GOOGLE_MAP_API_KEY when loading JS source
Google Maps recently changed their billing model which resulted in an API key always being required when using the Javascript API. If you want to see the map in development mode then set GOOGLE_MAP_API_KEY in $APP_ROOT/.env.local or change the one in $APP_ROOT/.env.development.
- Loading branch information
1 parent
b26961f
commit 3dc26fd
Showing
4 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GOOGLE_MAP_API_KEY=fake-google-map-api-key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module GoogleMapsApiHelper | ||
def google_maps_api_source_url | ||
api_key = ENV.fetch('GOOGLE_MAP_API_KEY') | ||
|
||
"https://maps.googleapis.com/maps/api/js?key=#{api_key}®ion=GB&libraries=geometry" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GoogleMapsApiHelper, '#google_maps_api_source_url' do | ||
it 'returns a URL which includes the API key' do | ||
allow(ENV).to receive(:fetch).with('GOOGLE_MAP_API_KEY').and_return('fake-key') | ||
|
||
expect(google_maps_api_source_url).to eq( | ||
'https://maps.googleapis.com/maps/api/js?key=fake-key®ion=GB&libraries=geometry' | ||
) | ||
end | ||
end |