Skip to content

Instantly share code, notes, and snippets.

@woods
Created May 30, 2013 03:16
Show Gist options
  • Save woods/5675532 to your computer and use it in GitHub Desktop.
Save woods/5675532 to your computer and use it in GitHub Desktop.
Helpers for embedding or displaying links to a Google map
module GoogleMapsHelper
# Returns a URL to use in an iframe for embedding a Google map
# Reference: http://asnsblues.blogspot.com/2011/11/google-maps-query-string-parameters.html
def google_maps_embed_url(address)
"#{google_maps_url(address)}&output=embed"
end
# Returns a URL to use for linking to a Google map
# Reference: http://asnsblues.blogspot.com/2011/11/google-maps-query-string-parameters.html
def google_maps_url(address)
"https://maps.google.com/maps?f=q&t=m&ie=UTF8&q=#{u address}"
end
end
<%= content_tag :iframe, nil,
src: google_maps_embed_url(@address),
width: 300,
height: 300,
frameborder: 0,
scrolling: 'no',
marginheight: 0,
marginwidth: 0 %>
<br />
<small>
<%= link_to "View Larger Map", google_maps_url(@address) %>
</small>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment