I am trying to implement google maps on angular 1.5 The map is rendering but markers are not appearing on the map. The project is using component based angular. I am attaching relevant code herewith. Please suggest.
(function () {
'use strict';
angular.module('angularstrapApp')
.controller('mapController', mapController);
chaptersController.$inject = ["$scope", "$http", "$window", "$q", "asyncService"];
function chaptersController($scope, $http, $window, $q, asyncService) {
var vm = this;
vm.Heading = "map";
vm.Text = "This is a sample page.";
return vm;
}
})();
#map {
height: 75vh;
}
body {
font: bold 12px Arial;
}
a {
text-decoration: none;
}
/*#map{
height:500px;
width:500px;
box-shadow: 3px 3px 10px gray;
}*/
#repeat{
display: inline;
}
#country_container {
width: 1000px;
margin: 13px 3px 3px 0px;
text-align: center;
width: 85px;
padding: 4px;
display: inline-table;
color: white;
background-color: black;
font-size: 12px;
cursor: pointer;
border: 1px solid black;
border-radius:13px;
}
#country_container:hover {
box-shadow: 0px 0px 10px black;
background-color: gray;
border: 1px solid gray;
cursor: pointer;
}
#names {
cursor: pointer;
}
<div id = "map"></div>
<div id="repeat" ng-repeat="marker in markers | orderBy : 'title'">
<a id="country_container" href="#" ng-click="openInfoWindow($event, marker)">
<label id="names" >{{marker.title}}</label></a>
</div>
<script>
var cities = [
{
city : 'chicago',
lat : 42.578924,
long : -88.560553
},
{
city : 'Arizona',
lat : 34.048927,
long : -111.093735
},
{
city : 'Arkansas',
lat : 35.489746,
long : -93.824272
},
{
city : 'California',
lat : 36.778259,
long : -119.417931
}
];
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 42.377254, lng: -87.934657},
zoom: 4
});
}
var markers = [];
var infoWindow = new google.maps.InfoWindow();
var createMarker = function (info){
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(info.lat, info.long),
title: info.city
});
// marker.content = '<div class="infoWindowContent">' + info.desc + '</div>';
google.maps.event.addListener(marker, 'click', function(){
infoWindow.setContent('<h2>' + marker.title); //+ '</h2>' + marker.content);
infoWindow.open(map, marker);
});
markers.push(marker);
}
for (i = 0; i < cities.length; i++){
createMarker(cities[i]);
}
marker.setMap(marker);
// $window.initialize = initialize;
openInfoWindow = function(e, selectedMarker){
e.preventDefault();
google.maps.event.trigger(selectedMarker, 'click');
}
</script>
<script src="node_modules/angular/angular.min.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC9vaOoEC1FPNIVfHMu0vlinnNhagjLsi4&callback=initMap" async defer></script>