Skip to content

Instantly share code, notes, and snippets.

@danielpuglisi
Forked from mcasimir/static_map_helper.rb
Last active January 27, 2017 14:54
Show Gist options
  • Save danielpuglisi/e2afb3aabcbd205f88922e7ffe137af4 to your computer and use it in GitHub Desktop.
Save danielpuglisi/e2afb3aabcbd205f88922e7ffe137af4 to your computer and use it in GitHub Desktop.
Google Maps Static map helper for Ruby on Rails
module StaticMapHelper
def static_map_for(location, options = {})
params = {
center: [location.latitude, location.longitude].join(","),
zoom: 15,
size: "300x300",
scale: 2,
markers: [location.latitude, location.longitude].join(","),
sensor: true,
key: ENV['GOOGLE_STATIC_MAPS_API_KEY']
}.merge(options)
query_string = params.map{|k,v| "#{k}=#{v}"}.join("&")
image_tag "https://maps.googleapis.com/maps/api/staticmap?#{query_string}", :alt => location.city
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment