Created
October 15, 2014 18:11
-
-
Save josephwegner/8309ffd144a12a07fe5d to your computer and use it in GitHub Desktop.
Loading Google Maps Asynchronously for angular-ui-maps
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
| 'use strict' | |
| reqModules = [ | |
| 'ui.router' | |
| 'ui.map' | |
| 'bitesApp.bites' | |
| 'google-maps-sdk' | |
| ] | |
| angular.module 'bitesApp.bite', reqModules | |
| .config ($stateProvider) -> | |
| $stateProvider | |
| .state 'bite', | |
| url: "#{Settings.BASE_URL}bites/:biteId" | |
| templateUrl: '/app/layouts/empty.html' | |
| controller: 'bitesDetailController' | |
| .controller 'bitesDetailController', ($scope, $stateParams, bitesBitesService, googleMapsService) -> | |
| googleMapsService.sdk().then (gMaps) -> | |
| console.log "hit" | |
| console.log gMaps |
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
| 'use strict' | |
| angular.module 'google-maps-sdk', [] | |
| .factory 'googleMapsService', ($document, $q, $rootScope) -> | |
| sdkLoadDefer = $q.defer() | |
| window.onGoogleMapsLoad = -> | |
| $rootScope.$apply -> | |
| sdkLoadDefer.resolve(window.google.maps) | |
| scriptTag = $document[0].createElement "script" | |
| scriptTag.type = "text/javascript" | |
| scriptTag.async = true | |
| scriptTag.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=onGoogleMapsLoad" | |
| body = $document[0].getElementsByTagName("body")[0] | |
| body.appendChild scriptTag | |
| sdk: -> | |
| sdkLoadDefer.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment