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 = {};
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');
},
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();
$scope.currentLocation = {lat : $scope.center.lat(), lng : $scope.center.lng()};
console.log('$scope.currentLocation', $scope.currentLocation);
*/
console.log('function i want to run ONCE after initial map load...');
})
});
myApp.service('myAppServices', function($http, $q, uiGmapGoogleMapApi) {
/*
*...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.