I am trying to send start point and end point to receive the route between these 2 points. this is the code that I have for receiving the route:
const calculateRoute = async () => {
if (originPosition && destinationPosition) {
const origin = `${originPosition.lat},${originPosition.lng}`;
const destination = `${destinationPosition.lat},${destinationPosition.lng}`;
console.log("Origin:", origin); // Log origin coordinates
console.log("Destination:", destination); // Log destination coordinates
try {
const response = await axios.get(
`https://graphhopper.com/api/1/route?point=${origin}&point=${destination}&vehicle=foot&locale=en&calc_points=true&key=3298a94b-9a17-49ee-a2c4-d756d163c7b8`
);
console.log("API response:", response.data);
if (
response.data &&
response.data.paths &&
response.data.paths.length > 0
) {
const route = response.data.paths[0];
if (route.points && route.points.coordinates) {
const coordinates = route.points.coordinates.map((coord) => [
coord[1],
coord[0],
]);
setRouteCoordinates(coordinates);
} else {
console.error("No coordinates found in route");
}
} else {
console.error("No routes found");
}
} catch (error) {
console.error("Error fetching directions:", error.message);
}
}};
I know that the origin and destination are not null values and that the error comes from an empty response. What am I missing and what can I do to debbug it further???