Created
July 23, 2012 00:34
-
-
Save ptn/3161485 to your computer and use it in GitHub Desktop.
Revisions
-
ptn created this gist
Jul 23, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ $(document).ready -> if $("#map").length > 0 class MapManager constructor: -> @defaultLat = -12.043333 @defaultLng = -77.028333 @latEl = $("#experience_latitude") @lngEl = $("#experience_longitude") coords = @initialCoords() @map = new GMaps div: "#map" lat: coords.lat lng: coords.lng zoom: 15 @map.addMarker lat: coords.lat lng: coords.lng @bindForm() bindForm: -> $("#geocoding a.button").click (e) => e.preventDefault() GMaps.geocode address: $('#city').val().trim() callback: (results, status) => if status == 'OK' latlng = results[0].geometry.location @moveMap(latlng.lat(), latlng.lng()) @latEl.val(latlng.lng()) @lngEl.val(latlng.lat()) initialCoords: -> coords = {} lat = @latEl.val() lat = @defaultLat unless lat coords.lat = lat lng = @lngEl.val() lng = @defaultLng unless lng coords.lng = lng coords moveMap: (lat, lng) -> @map.setCenter(lat, lng) @map.removeMarkers @map.addMarker lat: lat lng: lng map = new MapManager