Skip to content

Commit 163a0e7

Browse files
committed
Make Google Maps Static API key optional.
1 parent befaded commit 163a0e7

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ TR_API_KEY=yourapikey
1010
TR_BASE_URI=https://www.taskrabbit.com
1111

1212
# Google Static Maps API Key (https://developers.google.com/maps/documentation/javascript/tutorial#api_key)
13-
# An API key is not required to use the Google Static Maps API, but this app is set up to use one.
13+
# An API key is not required to use the Google Static Maps API, but there is a 640px max size limit
14+
# when using it without a key (map on the new order page is 700px wide).
1415
GMAPS_STATIC_API_KEY=yourgmapsapikey

app/assets/javascripts/burgertome.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ BurgerToMe = {
2727
var zoom = 12;
2828
var size = "700x200";
2929

30-
var map_image_base_url = "//maps.googleapis.com/maps/api/staticmap?size="+size+"&maptype=roadmap&sensor=false&key="+this.GMAPS_STATIC_API_KEY;
30+
var map_image_base_url = "//maps.googleapis.com/maps/api/staticmap?size="+size+"&maptype=roadmap&sensor=false";
31+
if (this.GMAPS_STATIC_API_KEY) {
32+
map_image_base_url += "&key="+this.GMAPS_STATIC_API_KEY
33+
}
3134

3235
var field_name_map = _({ // this object maps our form fields to google maps place object fields
3336
'address_address': ['street_number', 'route'],

app/views/orders/show.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<section class="location boxed">
4747
<header>Deliver To: <span class="address"><%= @order.location %></span></header>
4848
<article>
49-
<img class="location_map" src="//maps.googleapis.com/maps/api/staticmap?size=700x200&center=<%= @order.lat_lng_for_url %>&markers=size:large%7Ccolor:red%7C<%= @order.lat_lng_for_url %>&zoom=15&maptype=roadmap&sensor=false&key=<%= ENV['GMAPS_STATIC_API_KEY'] %>">
49+
<img class="location_map" src="//maps.googleapis.com/maps/api/staticmap?size=700x200&center=<%= @order.lat_lng_for_url %>&markers=size:large%7Ccolor:red%7C<%= @order.lat_lng_for_url %>&zoom=15&maptype=roadmap&sensor=false<%= "&key=#{ENV['GMAPS_STATIC_API_KEY']}" if ENV['GMAPS_STATIC_API_KEY'] %>">
5050
</article>
5151
</section>
5252
</div>

0 commit comments

Comments
 (0)