Created
November 6, 2011 20:14
-
-
Save rkotov93/1343403 to your computer and use it in GitHub Desktop.
CoffeeScript closures
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
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