-
-
Save danielpuglisi/e2afb3aabcbd205f88922e7ffe137af4 to your computer and use it in GitHub Desktop.
Google Maps Static map helper for Ruby on Rails
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
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