I fetch this array from server :
[{
"res_id": 0,
"res_name": "string",
"res_desc": "string",
"res_address": "string"
},
etc
]
I have to display a list of markers on map, so I map my restos into marker to populate the coords, the first problem is with the data i get from server, its an adress, so then I call:
restos.forEach(x => FetchGeocoder(x.res_address));
To then fetch with geocoder:
const FetchGeocoder = async (address) => {
const response = await fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' +
address + ',' +
'CABA&key=' + "KEY")
const responseData = await response.json();
const markers = responseData.results[0].geometry.location;
restos.forEach(x => {
x.res_coords = {
latitude: markers.lat,
longitude: markers.lng
}
});
};
The problem I cant resolve is that I get 3 coords objects, because I have 3 restos in my array, but only 1 coords object is assigned to all of my restos, instead of each coords beeing asigned to the correct resto.
Thanks in advance for any help or assistance!