Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Created November 6, 2011 20:14
Show Gist options
  • Save rkotov93/1343403 to your computer and use it in GitHub Desktop.
Save rkotov93/1343403 to your computer and use it in GitHub Desktop.
CoffeeScript closures
class window.MapHandler
map = null
makeMap: () ->
latlng = new google.maps.LatLng(54.711929,20.5089);
myOptions =
zoom: 12
center: latlng
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions)
@geocode("Калининград, Чернышевского 101")
iAmHere: (address) ->
location = @geocode(address)
placeMarker(location)
placeMarker: (location) ->
marker = new google.maps.Marker(
position: location
map: @map)
geocode: (address) ->
geocoder = new google.maps.Geocoder
geocoder.geocode(
'address': address,
(results, status) =>
if status is google.maps.GeocoderStatus.OK
alert results[0].geometry.location
map.setCenter(results[0].geometry.location)
@placeMarker(results[0].geometry.location)
else alert("Geocode was not successful for the following reason: " + status);
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment