I have a JSON object with some entries (Appointments) each thereof an "location id". Then I loop trough these entries and emit a request to my nodeJS server by socketIO to get data from document with the location id.
At the end I need an array with the data of lat/lng to create some marker on a map.
Here is the code:
//controller for showing map
.controller('MapCtrl', function($scope, socket){
socket.emit('getApp', staticUserid);
socket.on('getApps', function (appdata) {
var locArr = [];
for (var i = 0; i < appdata.length; i++) {
if (appdata[i].locationid != '') {
locArr.push(appdata[i].locationid);
}
}
var LatLngArr = [];
for (var j = 0; j < locArr.length; j++) {
socket.emit('getLocation', locArr[j]);
socket.on('getLoc', function (locData) {
console.log('received lat/lng: ' + locData.lat + '/' + locData.lng);
if (!LatLngArr[j]) LatLngArr[j] = []
LatLngArr[j][0] = locData.lat;
LatLngArr[j][1] = locData.lng;
});
}
//console.log('test:'+LatLngArr[0][0]);
});
var newMarkers = [[52.549678, 13.3879516],[52.5442992, 13.352809],[52.5186283,13.3761181]]; // this should be the generated array
var newCenter = [52.549678, 13.3879516];
createMap(newCenter,newMarkers);
})
The problem is, that the var LatLngArr isn't defined out of the...
socket.on('getLoc', function (locData)
It would be very nice if somebody can help me :-)
Thanks so much!