I’m brand new to Coffeescript and struggling on the syntax. Can anyone help me with how the following should be written in CS?
$("#getLocation").click(function() {
$('#location-loading').show();
navigator.geolocation.getCurrentPosition(applyLocation);
return false;
});
function applyLocation(location) {
$('#LogLongitude').val(location.coords.longitude);
$('#LogLatitude').val(location.coords.latitude);
alert('Latitude:' + location.coords.latitude + ', Longitude: ' + location.coords.longitude + ', Accuracy: ' + location.coords.accuracy);
$('#location-loading').hide();
}
I thought the following would work, but I am getting errors with calling the function and returning false (so I don’t follow the link).
$('#getLocation').click ->
$('#location-loading').show()
navigator.geolocation.getCurrentPosition(applyLocation)
false
applyLocation = (location) ->
$('#LogLongitude').val(location.coords.longitude)
$('#LogLatitude').val(location.coords.latitude)
alert('Latitude:' + location.coords.latitude + ', Longitude: ' + location.coords.longitude + ', Accuracy: ' + location.coords.accuracy)
$('#location-loading').hide()
You can omit the
()parethesis for simple function calling (not chained)and put the string in the lower part into double-quota to be able to use the
#{}syntax,but except that your code does look quite coffeeish already 😉