1

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
3
  • is data.rows or data shown in the console after executing? Commented Feb 29, 2016 at 7:39
  • @Riccardo Yeah it is showing, an array actually. i.imgur.com/aZT0DzV.png Commented 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. Commented Feb 29, 2016 at 9:17

1 Answer 1

2

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
1
  • I used the layers recommendation. Commented Mar 1, 2016 at 6:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.