I am trying to search a MySQL database based on the north, south, east, and west bounds of a map. I am using Nodejs with express. When I use postman or enter the url in with the LAT and LON for the search it will work just fine. The issue comes when I try to build the URL sting form the front-end. I get back and empty JSON object.
app.get('/search', (req, res) => {
try {
connection.query(`SELECT * FROM photos WHERE lat BETWEEN '${req.query.north}' and '${req.query.south}' and lng BETWEEN '${req.query.west}' and '${req.query.east}'`, function (error, results, fields) {
if (error) throw error;
//console.log(results);
res.send(results);
});
}
catch (exception_var) {
console.log("Error");
}
})
This is the front-end client
async function mysearch() {
myFeatureGroup.clearLayers();
const mapEast = map.getBounds().getEast().toString();
const mapWest = map.getBounds().getWest().toString();
const mapNorth = map.getBounds().getNorth().toString();
const mapSouth = map.getBounds().getSouth().toString();
// http://127.0.0.1:3000/search?north=42.06254817666338&south=43.002638523957906&east=-89.55780029296875&west=-91.41448974609375
// http://127.0.0.1:3000/search?north=${mapNorth}&south=${mapSouth}&east=${mapEast}&west=${mapWest}
fetch(`http://127.0.0.1:3000/search?north=${mapNorth}&south=${mapSouth}&east=${mapEast}&west=${mapWest}`)
.then(response => response.json())
.then(data => {
console.log(data);
});
}