hello, everyone. I am using custom function to do the map matching, but the return results are always {} . I do not what went wrong. Does anyone have any thoughts on this.
blew is my code.
collection.aggregate [ {
'$addFields': {
'coordinates': {
'$function': {
'body': """
function (locs){
const exports = async function (locs){
const radius = locs.map(() => 10);
const profile = 'driving';
const coordinates = locs.join(';');
let accessToken = "pk.eyJ1IjoiZnVzb3lvzusYHInOxXA6MmliSA";
const radiuses = radius.join(';');
const query = await fetch(
https://api.mapbox.com/matching/v5/mapbox/${profile}/${coordinates}? geometries=geojson&radiuses=${radiuses}&steps=true&access_token=${accessToken},
{ method: 'GET' }
);
const response = await query.json();
// Handle errors
if (response.code !== 'Ok') {
console.log(
${response.code} - ${response.message}
);
return 0;
}
const coords = response.matchings[0].geometry;
return coords;
}
return exports(locs);
}
""",
'args': ['$locs'],
'lang': "js"
},
}
}
},]