Skip to content

Instantly share code, notes, and snippets.

@GSto
Created June 2, 2013 21:17
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 GSto/c219aa6ab0043a3cad9d to your computer and use it in GitHub Desktop.
Save GSto/c219aa6ab0043a3cad9d to your computer and use it in GitHub Desktop.
example of places search in coffeescript
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$ ->
if $('#google_map').length > 0
#places search map and autocomplete
map_el = document.getElementById 'google_map'
search_el = document.getElementById 'places_search'
center = new google.maps.LatLng(33.958453, -83.375614)
#prevent submits on enter
$(search_el).keydown (e) -> e.keyCode != 13
map_options =
center: center
zoom: 16
mapTypeId: google.maps.MapTypeId.ROADMAP
scrollwheel: false
scaleControl: false
map = new google.maps.Map map_el, map_options
autocomplete = new google.maps.places.Autocomplete search_el
marker_options =
map: map
position: center
marker = new google.maps.Marker marker_options
google.maps.event.addListener autocomplete, 'place_changed', ->
place = autocomplete.getPlace()
map.panTo place.geometry.location
$("#place_name").val(place.name) if place.name
$("#place_address").val(place.formatted_address) if place.formatted_address
$("#place_address_line_1").val(place.formatted_address.split(",")[0]) if place.formatted_address
$("#place_city").val(place.formatted_address.split(",")[1]) if place.formatted_address
$("#place_state").val(place.formatted_address.split(",")[2].split(' ')[1])
$("#place_zipcode").val(place.formatted_address.split(",")[2].split(' ')[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment