title: Adding Google Maps to AngularJS & Ionic App
body: <p>I am trying to add a Google Maps application to give the user the directions from his/her current location to a particular fixed static point on the map.  So far I have created a controller and the related HTML.  However, for some reason when I am testing this out I am not getting the map, but rather an error in the console ""</p>
  
  <p>This is my controller:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>'use strict';
  angular.module('main')
    .controller('LocationCtrl', function($scope, $ionicLoading, $compile) {
      function initialize() {
        google.maps.event.addDomListener(window, 'load');
  
        var myLatlng = new google.maps.LatLng(43.07493, -89.381388);
  
        var mapOptions = {
          center: myLatlng,
          zoom: 16,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map"),
          mapOptions);
  
        //Marker + infowindow + angularjs compiled ng-click
        var contentString = "&lt;div&gt;&lt;a ng-click='clickTest()'&gt;Click me!&lt;/a&gt;&lt;/div&gt;";
        var compiled = $compile(contentString)($scope);
  
        var infowindow = new google.maps.InfoWindow({
          content: compiled[0]
        });
  
        var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          title: 'Uluru (Ayers Rock)'
        });
  
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map, marker);
        });
  
        $scope.map = map;
      }
  
      function loadScript(src) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        document.getElementsByTagName("head")[0].appendChild(script);
        script.src = src;
      }
  
      loadScript('http://www.google.com.mt/jsapi');
      loadScript('http://maps.googleapis.com/maps/api/js?key=&amp;v=3&amp;sensor=true&amp;callback=initialize');
  
  
  
      $scope.centerOnMe = function() {
        if (!$scope.map) {
          return;
        }
  
        $scope.loading = $ionicLoading.show({
          content: 'Getting location',
          showBackdrop: false
        });
  
        navigator.geolocation.getCurrentPosition(function(pos) {
          $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
          $scope.loading.hide();
        }, function(error) {
          alert('Unable to get location: ' + error.message);
        });
      };
  
      $scope.clickTest = function() {
        alert('Example of infowindow with ng-click')
      };
  
    });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"&gt;&lt;/script&gt;
  &lt;link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet" /&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  &lt;ion-pane&gt;
    &lt;ion-header-bar class="bar-dark"&gt;
      &lt;button ui-sref="main" class="button button-icon icon ion-navicon"&gt;&lt;/button&gt;
      &lt;h1 class="title"&gt;Directions&lt;/h1&gt;
    &lt;/ion-header-bar&gt;
    &lt;ion-content&gt;
  
      &lt;div id="map" data-tap-disabled="true"&gt;&lt;/div&gt;
  
    &lt;/ion-content&gt;
  
    &lt;ion-footer-bar class="bar-dark"&gt;
      &lt;a ng-click="centerOnMe()" class="button button-icon icon ion-navigate"&gt;Find Me&lt;/a&gt;
    &lt;/ion-footer-bar&gt;
  &lt;/ion-pane&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Can someone tell me what I am doing wrong?  Also, can some one give me some tips on how to give the user the directions to this static point when the user clicks on the Find Me link in the footer? (Something along these lines but the end point is fixed and the start point would be the location of the user when he clicks on the Find Me button - <a href="https://developers.google.com/maps/documentation/javascript/examples/directions-panel" rel="nofollow">https://developers.google.com/maps/documentation/javascript/examples/directions-panel</a>)</p>
  
  <p>I am new to AngularJS and am not sure if my code is correct.  Also, I am not using jQuery as a dependency.</p>