While utilizing the Google Maps API and AngularJS (1.5.8), I encountered an issue where I couldn't access markers that were created in a loop. The code snippet below is located inside the initMap function:
var markers = [];
for(var i=0; i<10; i++){
var html = $scope.posts[i].address;
var marker = new google.maps.Marker({
map: map,
position: {lat: parseFloat($scope.posts[i].lat), lng: parseFloat($scope.posts[i].lng)}
});
markers.push(marker);
bindInfoWindow(markers[i], map, infoWindow, html);
}
markers // no error messages, nothing
console.log(markers); // still nothing
EDIT:
The error was in
for(var i=0; i<10; i++){
Changed to:
for(var i=0; i<$scope.posts.length; i++)
I am grateful for @Maxx's guidance and appreciation of everyone who attempted to assist. This turned out to be a simple oversight.