Last active
January 4, 2016 01:19
-
-
Save andrewxhill/8547753 to your computer and use it in GitHub Desktop.
CartoDB SQL results plus jQuery
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>jQuery - Display SQL Results</title> | |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.core.js"></script> | |
</head> | |
<body> | |
<h4>Line name: length</h4> | |
<ul class="results"> | |
</ul> | |
<script> | |
$(function() { | |
var sql = cartodb.SQL({ user: 'andrew' }); | |
sql.execute("SELECT line, (ST_Length(the_geom::geography)/1000)::int length FROM nyc_subway_routes ORDER BY ST_Length(the_geom) DESC LIMIT 20").done(function(data) { | |
for (i in data.rows){ | |
var newelement = $('<li></li>'); | |
newelement | |
.attr('id', data.rows[i].line) | |
.html('<span>'+data.rows[i].line+'</span>: '+data.rows[i].length+' km'); | |
$('.results').append(newelement); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment