Within my map, I have designated various locations with markers. Once a marker is clicked, an infowindow appears containing the place's name and a button. To capture these places in an array when the button within the infowindow is clicked, I require a function.
Below is the code snippet:
$scope.routes = [];
locations = data;
$scope.map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: new google.maps.LatLng(12.9716, 77.5946),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
$scope.infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
icon: {
url: 'img/map-marker.png',
scaledSize: new google.maps.Size(25, 25)
},
position: new google.maps.LatLng(locations[i].Latitude, locations[i].Longitude),
map: $scope.map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var content1 = locations[i].Name + '<button class="btn btn-success" ng-click="AddLoc(\'' + locations[i].Name + '\');">Add</button>';
var content = $compile(content1)($scope);
$scope.infowindow.setContent(content[0]);
$scope.infowindow.open($scope.map, marker);
}
})(marker, i));
}
$scope.AddLoc = function(x) {
$scope.routes.push(x);
alert($scope.routes);
}
However, upon clicking a marker while running the code, it throws an error.
An exception occurred at line 31, column 318 in http://ajax.googleapis.com ajax/libs/angularjs/1.5.8/angular.min.js
0x800a139e - JavaScript runtime error: [jqLite:nosel] http://errors.angularjs.org/1.5.8/jqLite/nosel
I would greatly appreciate any assistance or guidance in resolving this issue.