I am currently looping through an array of location objects. I am then calling out to google to get me a panorama for that location. The problem is the request for this is asynchronous, so when the callback actually gets called, the location variable I passed is the last location in the array.
Here is example code, and console log output:
for location in paginated_data.locations
console.log location
latLng = new google.maps.LatLng(location.latitude,location.longitude)
@sv.getPanoramaByLocation(latLng, 50, (StreetViewPanoramaData, StreetViewStatus) =>
console.log location
)
As you can see, in the initial loop the console sees the correct location, in the callback, it only shows the last one from the loop. Can anyone point me in the right direction on how to fix this?