Last active
August 29, 2015 13:57
-
-
Save oleics/9529516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('demo', []) | |
.provider('googleMaps', require('./google-maps-service-provider')) | |
.config(['googleMapsProvider', function(googleMapsProvider) { | |
googleMapsProvider.configure({ | |
key: 'your api key', | |
language: 'de', | |
libraries: 'places' | |
}); | |
}]) | |
.controller('MapController', ['googleMaps', function(googleMaps) { | |
googleMaps.then(function(googleMaps) { | |
// now we can extend google-maps-classes | |
function MarkerLabel_() { | |
} | |
inherits(MarkerLabel_, googleMaps.OverlayView); | |
}); | |
}]) | |
; | |
function inherits(childCtor, parentCtor) { | |
/** @constructor */ | |
function tempCtor() {} | |
tempCtor.prototype = parentCtor.prototype; | |
childCtor.superClass_ = parentCtor.prototype; | |
childCtor.prototype = new tempCtor(); | |
/** @override */ | |
childCtor.prototype.constructor = childCtor; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = [GoolgMapsServiceProvider]; | |
function GoolgMapsServiceProvider() { | |
// Some nice default options | |
this.options = { | |
// key: 'api-key here', | |
v: '3.15', | |
libraries: 'places', | |
language: 'en', | |
sensor: 'false' | |
}; | |
// A function that lets us configure options of the service | |
this.configure = function(options) { | |
angular.extend(this.options, options); | |
}; | |
// Return an instance of the service | |
this.$get = ['$q', function($q) { | |
return new GoolgMapsService($q, this.options); | |
}]; | |
} | |
// The service, that is a promise for a reference to window.google.maps | |
function GoolgMapsService($q, options) { | |
var deferred = $q.defer(); | |
// Early-resolve if google-maps-api is already in global-scope | |
if(typeof window.google !== 'undefined' && typeof window.google.maps !== 'undefined') { | |
deferred.resolve(window.google.maps); | |
return deferred.promise; | |
} | |
var randomizedFunctionName = options.callback = 'onGoogleMapsReady' + Math.round(Math.random()*1000); | |
window[randomizedFunctionName] = function() { | |
window[randomizedFunctionName] = null; | |
// Resolve the promise | |
deferred.resolve(window.google.maps); | |
}; | |
var q = []; | |
angular.forEach(options, function(v, k) { | |
q.push(k+'='+v); | |
}); | |
q = q.join('&'); | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = 'https://maps.googleapis.com/maps/api/js?' + q; | |
document.body.appendChild(script); | |
// Return the promise | |
return deferred.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
attempting to use this, it is not working.. any help is useful and appreciated
https://github.com/nlaplante/angular-google-maps/tree/master_maps_loader