this is my query in postman {{URL}}/api/v1/tours/tours-within/233/center/34.111745,-118.113491/unit/mi
and this is my code in Node.js
on the routes
router
.route('/tours-within/:distance/center/:latlng/unit/:unit')
.get(tourController.getToursWithin);
in controller
exports.getToursWithin = (req, res, next) => {
const { distance, latlng, unit } = req.params;
const { lat, lng } = latlng.split(',');
if (!lat || !lng) {
next(
new AppError(
'Please provide latitude and longitude in the format lat,lng',
400
)
);
}
console.log(distance, lat, lng, unit);
res.status(200).json({
status: 'success'
});
};
I am from Paraguay and I am testing a latitude and longitude of Los Angeles but I don't know if the distance that I pass is wrong. How can I know what distance to enter?
Your problem is in this line
When you do a
.split
, you do it on a string, eg:"123,456"
and it returns an array.With the operation you have on the left in the original code you are doing an Object destructuring , but in reality you should do an Array destructuring , so you should have your code like this: