I am using cartodb api to fetch the geojson from the cartodb data set using this code
var map = L.map('map',{ center: [-35.1393961, 149.8530818], zoom: 13});
var alpha=map.getBounds();
var lat0=alpha.getNorthEast().lat;
var long0=map.getBounds().getNorthEast().lng;
var lat1=map.getBounds().getSouthWest().lat;
var long1=map.getBounds().getSouthWest().lng;
// Add Tile Layer basemap
L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v10/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiaGFzaGlyaWx5YXMiLCJhIjoiY2l4NzdzMmhjMDB0dDJ0bXN0NW5jc3cwayJ9.UNDyJQP92EC0ToFilX28lA', {
maxZoom: 18,
id: 'your.mapbox.project.id',
accessToken: 'your.mapbox.public.access.token'}).addTo(map);
// Global Variables
// Will go here
var coffeeShopLocations = null;
// Database Queries
// Get all coffee cafes from dataset
var sqlQuery = "SELECT * FROM zearch_nsw_19042016 WHERE the_geom && ST_MakeEnvelope("+long1+", "+lat1+", "+long0+", "+lat0+", 4326);";
function showAll(){
$.getJSON("https://{username}.carto.com/api/v2/sql/?q="+sqlQuery+"&api_key={key}&format=geojson&callback=?", function(data) {
console.log(data);
});
};
// Run showAll function automatically when document loads
$( document ).ready(function() {
showAll();
});
While executing the query on the cartodb it is returning correct result but here at first it was showing invalid geom object but when I outputed the geojson it is showing this error
argument of WHERE must be type boolean, not type geometry
What is wrong? The query works fine when implemented on the cartodb or postgis database. But when used with cartodb api it generates the error on geojson