var myApp = angular.module('app', ['uiGmapgoogle-maps']);
myApp.config(function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: '',
v: '3',
libraries: 'weather,geometry,visualization'
});
});
myApp.controller('MainCtrl', function($scope, uiGmapGoogleMapApi, myAppServices, uiGmapIsReady) {
$scope.myCurrentLocation = {};
var initialMapLoad = 0;
myAppServices.getCurrentLocation()
.then(function(myCurrentLocation){
$scope.myCurrentLocation = myCurrentLocation;
})
.then(function(){return uiGmapGoogleMapApi;})
.then(function(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;
});
uiGmapIsReady.promise() // this gets all (ready) map instances - defaults to 1 for the first map
.then(function(instances) { // instances is an array object
var maps = instances[0].map; // if only 1 map it's found at index 0 of array
$scope.myOnceOnlyFunction(maps); // this function will only be applied on initial map load (once ready)
});
$scope.myOnceOnlyFunction = function(maps){
var center = maps.getCenter();
var lat = center.lat();
var lng = center.lng();
alert('I\'ll only say this once ! \n Lat : ' + lat +...
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.