Skip to content

Instantly share code, notes, and snippets.

@azcoov
Forked from mcasimir/static_map_helper.rb
Created March 8, 2017 04:17
Show Gist options
  • Save azcoov/84e9b94bfc9aad696888484ce96540b0 to your computer and use it in GitHub Desktop.
Save azcoov/84e9b94bfc9aad696888484ce96540b0 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.lat, location.lng].join(","),
:zoom => 15,
:size => "300x300",
:markers => [location.lat, location.lng].join(","),
:sensor => true
}.merge(options)
query_string = params.map{|k,v| "#{k}=#{v}"}.join("&")
image_tag "http://maps.googleapis.com/maps/api/staticmap?#{query_string}", :alt => location.name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment