angular-google-maps
http://stackoverflow.com/questions/28247260
HTML
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.6/fullcalendar.min.css">
<title>Angular Google Maps</title>
<script src="https://code.angularjs.org/1.3.10/angular.js"></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js'></script>
<script src='//rawgit.com/angular-ui/angular-google-maps/master/dist/angular-google-maps.js'></script>
<body ng-app="app">
<div class="angular-google-map-container" ng-controller="MainCtrl">
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="map.options" events="map.events" control="googlemap">
</ui-gmap-google-map>
</div>
</body>
CSS
.angular-google-map-container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
JavaScript
var myApp = angular.module('app', ['uiGmapgoogle-maps']);
myApp.config(function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: '',
v: '3.18',
libraries: 'weather,geometry,visualization'
});
});
myApp.controller('MainCtrl', function($scope, uiGmapGoogleMapApi, myAppServices) {
$scope.myCurrentLocation = {};
var initialMapLoad = 0;
console.log('initialMapLoad', initialMapLoad);
myAppServices.getCurrentLocation()
.then(function(myCurrentLocation){
console.log('myCurrentLocation', myCurrentLocation);
$scope.myCurrentLocation = myCurrentLocation;
})
.then(function(){return uiGmapGoogleMapApi;})
.then(function(maps){
console.log('maps', maps);
$scope.googlemap = {};
$scope.map = {
center: { // set on San Francisco as initial default
latitude: 37.7749295,
longitude: -122.4194155
},
zoom: 13,
pan: 1,
options: myAppServices.getMapOptions().mapOptions,
control: {},
events: {
tilesloaded: function (maps, eventName, args) {
console.log('The ' + eventName + ' function fires every time you move or zoom the map');
console.log('initialMapLoad', initialMapLoad);
if(initialMapLoad === 0){
alert(maps.getBounds());
initialMapLoad = 1;
}
},
dragend: function (maps, eventName, args) {
console.log('The ' + eventName + ' function fires every time you drag the map');
},
zoom_changed: function (maps, eventName, args) {
console.log('The ' + eventName + ' function fires every time you zoom');
}
}
};
$scope.map.center = $scope.myCurrentLocation;
console.log('maps', maps.LatLngBounds);
/* this section of code won't run because maps is not defined at this point
$scope.mapBounds = maps.Map.getBounds();
$scope.center = $scope.mapBounds.getCenter();
...