Skip to content

Instantly share code, notes, and snippets.

@matthewlehner
Created August 30, 2012 01:11
Show Gist options
  • Save matthewlehner/3521355 to your computer and use it in GitHub Desktop.
Save matthewlehner/3521355 to your computer and use it in GitHub Desktop.
Google Maps Images API view helper method for Rails
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
@matthewlehner
Copy link
Author

Add this to whatever helper and call it in your view like a boss.

@matthewlehner
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment