I am a beginner, learning the cartodb-API. below is my javascript code which is below my body tag in the HTML page.
The map, together with the points are loading correctly but the SQL command is not executing.
<script>
function main() {
cartodb.createVis('map', 'https://user.cartodb.com/api/v2/viz/010577da-dea0-11e5-ad6a-0e5db1731f59/viz.json', {
tiles_loader: true,
center_lat: 0.5637,
center_lon: 3.896,
zoom: 4
})
.done(function(vis, layers) {
layers[1].setInteraction(true);
layers[1].on('featureOver', function(e, latlng, pos, data) {
console.log(e, latlng, pos, data);
});
var map = vis.getNativeMap();
map.setZoom(6);
})
.error(function(err) {
console.log(err);
});
var sql = new cartodb.SQL({user:'my_username'});
sql.execute("SELECT * FROM my_table_name WHERE car = 'XXXX'")
.done(function(data){
console.log(data.rows)
})
.error(function(errors){
console.log("errors" + errors);
})
}
window.onload = main;
</script>
wittich
2,3661 gold badge19 silver badges31 bronze badges
asked Feb 29, 2016 at 6:20
-
is data.rows or data shown in the console after executing?Riccardo– Riccardo2016年02月29日 07:39:35 +00:00Commented Feb 29, 2016 at 7:39
-
@Riccardo Yeah it is showing, an array actually. i.imgur.com/aZT0DzV.pngandrew– andrew2016年02月29日 09:15:10 +00:00Commented Feb 29, 2016 at 9:15
-
You need to out the points on the map as a layer. now the objects are simple JS objects. in leaflet you would define a map and add those layers to the map! The sql.execute just asks the DB to give you the results of the data as JSON but will not alter the visualization.Riccardo– Riccardo2016年02月29日 09:17:58 +00:00Commented Feb 29, 2016 at 9:17
1 Answer 1
As @riccardo is telling you on the comments the SQL API call will only retrieve the data but it won't do anything else with that information. Check this example on retrieving polygons to add them for highlighting on hover.
answered Feb 29, 2016 at 9:58
-
I used the layers recommendation.andrew– andrew2016年03月01日 06:45:22 +00:00Commented Mar 1, 2016 at 6:45
default