在我的地圖中,我用標記標記了幾個地方。如果我點擊某個標記,則會打開一個infowindow,其中顯示了該地點的名稱和一個按鈕。我需要編寫一個函數,當單擊infowindow中的按鈕時將這些位置添加到數組中。infowindow中的按鈕angularjs
我的代碼如下
$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);
}
當我運行的代碼和標記單擊它拋出一個錯誤
Unhandled exception 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
請幫我
這是你的31線嗎? –
錯誤是運行時錯誤。它不是我的代碼的一部分。它從鏈接拋出提供 – Alan