Created
August 30, 2012 01:11
-
-
Save matthewlehner/3521355 to your computer and use it in GitHub Desktop.
Google Maps Images API view helper method for 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
def map_image(lat, lng, options = {}) | |
options[:zoom] ||= '14' | |
options[:dimensions] ||= '125x125' | |
options[:sensor] ||= false | |
options[:scale] ||= '1' # Pixel density, '2' for Retina. | |
options[:marker_size] ||= 'small' | |
options[:alt] ||= '' | |
url = "http://maps.googleapis.com/maps/api/staticmap?size=#{options[:dimensions]}&zoom=#{options[:zoom]}&sensor=#{options[:sensor]}&markers=size:#{options[:marker_size]}|#{lat},#{lng}" | |
# This might be necessary to make it work. | |
# url = URI.encode( url ) | |
image_tag url, size: options[:dimensions], alt: options[:alt] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to whatever helper and call it in your view like a boss.