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.

  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].on('featureOver', function(e, latlng, pos, data) {
        console.log(e, latlng, pos, data);
      var map = vis.getNativeMap();
    .error(function(err) {

    var sql = new cartodb.SQL({user:'my_username'});
    sql.execute("SELECT * FROM my_table_name WHERE car = 'XXXX'")
      console.log("errors" + errors);
  window.onload = main;
  • is data.rows or data shown in the console after executing? – Riccardo Feb 29 '16 at 7:39
  • @Riccardo Yeah it is showing, an array actually. i.imgur.com/aZT0DzV.png – 1088 Feb 29 '16 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 Feb 29 '16 at 9:17

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.

  • I used the layers recommendation. – 1088 Mar 1 '16 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.