Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
Last active December 11, 2015 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixeltrix/4525387 to your computer and use it in GitHub Desktop.
Save pixeltrix/4525387 to your computer and use it in GitHub Desktop.
def maps_url(options = {})
options = options.dup
options.assert_valid_keys(:lat, :lng, :zoom, :width, :height)
options[:size] = “#{options.delete(:width)}x#{options.delete(:height)}”
options[:center] = “#{options.delete(:lat)},#{options.delete(:lng)}”
“http://maps.google.com/?#{options.to_query}”
end
>> helper.maps_url lat: 51.4651204, lng: -0.1148897, zoom: 15, width: 640, height: 220
=> "http://maps.google.com/?center=51.4651204%2C-0.1148897&size=640x220&zoom=15"
>> helper.link_to "Map", helper.maps_url(lat: 51.4651204, lng: -0.1148897, zoom: 15, width: 640, height: 220)
=> "<a href=\"http://maps.google.com/?center=51.4651204%2C-0.1148897&amp;size=640x220&amp;zoom=15\">Map</a>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment