Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Last active January 4, 2016 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewxhill/8547753 to your computer and use it in GitHub Desktop.
Save andrewxhill/8547753 to your computer and use it in GitHub Desktop.
CartoDB SQL results plus jQuery
<!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