I'm currently using Vue, nuxt3, and javascript for a front project.
My goal right now is to create a function that gets the distance between to city given in the parameters. So I wanted to use the google matrix API.
This is what I've tried to do :
const getDistance = async (town, center) => {
const response = await fetch(
`https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${town}&origins=${center}&units=imperial&key=API_KEY`
);
const data = await response.json();
console.log(data);
return data.rows[0].elements[0].distance.value;
};
But I keep receiving this error on the console:
(reason: cors header ‘access-control-allow-origin’ missing). status code: 200
I've already tried the HTTPS link request on google and that's working, seems like the error doesn't come from my API_KEY or something. Could someone help me?