The following code finds the current geographic location of iPhone users at boot time and loads the Google map accordingly using the directive.
Unfortunately, the geolocationData data variable from the directive does not apply to the html footer {{geolocationData}} ...
So, how can I pass in this case geolocationData opposite the directive to the html page and / or controller.
Thank.
Directive
'use strict';
angular.module('MyApp.directives', ['ngCordova'])
.directive('map', function($cordovaGeolocation) {
return {
restrict: 'E',
scope: {
onCreate: '&'
},
link: function ($scope, $element, $attr) {
function initialize() {
if ( !$scope.geolocationData ) {
$scope.geolocationData = {};
}
$cordovaGeolocation
.getCurrentPosition()
.then(function (position) {
var lat = position.coords.latitude
$scope.geolocationData.latitude = lat;
var long = position.coords.longitude
$scope.geolocationData.longitude = long;
console.log("POSITION: ", lat, long);
var mapOptions = {
center: new google.maps.LatLng(lat, long),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($element[0], mapOptions);
$scope.onCreate({map: map});
google.maps.event.addDomListener($element[0], 'mousedown', function (e) {
e.preventDefault();
return false;
});
}, function(err) {
});
}
google.maps.event.addDomListener(window, 'load', initialize);
}
};
});
And the following controller:
'use strict';
angular.module('MyApp.controllers', ['ngCordova'])
.controller('MapCtrl', function($scope, $ionicLoading, $cordovaGeolocation) {
if ( !$scope.geolocationData ) {
$scope.geolocationData = {};
}
};
And the following html fragment:
<body ng-app="MyApp" ng-controller="MapCtrl">
<ion-content scroll="false" style="bottom:50%;">
<map on-create="mapCreated(map)"></map>
</ion-content>
<ion-footer-bar class="bar-stable">
{{geolocationData}}
</ion-footer-bar>
</body>