@@ -53,7 +53,7 @@ app.controller('AppCtrl', function($scope, $ionicModal, $timeout, $http) {
53
53
_ . each ( resp . data , function ( datum ) {
54
54
new google . maps . Marker ( {
55
55
position : datum . l ,
56
- map : map ,
56
+ map : m . map ,
57
57
title : 'Forage Map'
58
58
} ) ;
59
59
} )
@@ -77,7 +77,8 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
77
77
coordinates : {
78
78
lat : '' ,
79
79
lng : ''
80
- }
80
+ } ,
81
+ map : { }
81
82
}
82
83
83
84
// Action
@@ -92,7 +93,7 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
92
93
var pos = new google . maps . LatLng ( position . coords . latitude , position . coords . longitude ) ;
93
94
94
95
var marker = new google . maps . Marker ( {
95
- map : $scope . map ,
96
+ map : m . map ,
96
97
position : pos ,
97
98
title : 'Forage Map'
98
99
} ) ;
@@ -103,10 +104,10 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
103
104
lng : pos . F
104
105
} ;
105
106
106
- // Broadcast map:geolocated event
107
+ // Broadcast map:geolocated event to reverse geo directive
107
108
$scope . $broadcast ( 'map:geolocated' , m . coordinates ) ;
108
109
109
- $scope . map . setCenter ( pos ) ;
110
+ m . map . setCenter ( pos ) ;
110
111
$ionicLoading . hide ( ) ;
111
112
} ) ;
112
113
} ,
@@ -115,9 +116,9 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
115
116
116
117
geocoder . geocode ( { 'address' : address } , function ( results , status ) {
117
118
if ( status == google . maps . GeocoderStatus . OK ) {
118
- $scope . map . setCenter ( results [ 0 ] . geometry . location ) ;
119
+ m . map . setCenter ( results [ 0 ] . geometry . location ) ;
119
120
var marker = new google . maps . Marker ( {
120
- map : $scope . map ,
121
+ map : m . map ,
121
122
position : results [ 0 ] . geometry . location
122
123
} ) ;
123
124
} else {
@@ -142,15 +143,16 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
142
143
143
144
var map = new google . maps . Map ( document . getElementById ( 'map-canvas' ) , mapOptions ) ;
144
145
145
- $scope . map = map ;
146
+ // bind
147
+ m . map = map ;
146
148
} ;
147
149
148
150
/**
149
151
* Builds Google Map Markers
150
152
*/
151
153
function buildGmarkers ( ) {
152
154
// Build map prior before building markers
153
- if ( angular . isUndefined ( $scope . map ) ) {
155
+ if ( angular . isUndefined ( m . map ) ) {
154
156
buildGmap ( ) ;
155
157
}
156
158
@@ -167,12 +169,12 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
167
169
lat : 39.952641 ,
168
170
lng : - 75.164052
169
171
} ,
170
- map : $scope . map ,
172
+ map : m . map ,
171
173
title : 'Forage Map'
172
174
} ) ;
173
175
174
176
google . maps . event . addListener ( marker , 'click' , function ( ) {
175
- infowindow . open ( $scope . map , marker ) ;
177
+ infowindow . open ( m . map , marker ) ;
176
178
} ) ;
177
179
}
178
180
@@ -198,7 +200,7 @@ app.controller('MapCtrl', function($scope, $ionicLoading, $compile, $http) {
198
200
lat : data . l [ 0 ] ,
199
201
lng : data . l [ 1 ]
200
202
} ,
201
- map : map ,
203
+ map : m . map ,
202
204
title : 'Forage Map'
203
205
} ) ;
204
206
} )
@@ -232,18 +234,19 @@ app.directive('reverseGeocode', function () {
232
234
233
235
geocoder . geocode ( { 'latLng' : latlng } , function ( results , status ) {
234
236
if ( status == google . maps . GeocoderStatus . OK ) {
237
+
235
238
if ( results [ 1 ] ) {
236
239
scope . success = true ;
237
240
scope . currentAddress = results [ 1 ] . formatted_address ;
238
241
} else {
239
242
scope . success = false ;
240
243
scope . failureMsg = 'Location not found' ;
241
244
}
245
+
242
246
} else {
243
247
scope . success = false ;
244
248
scope . currentAddress = 'Geocoder failed due to: ' + status ;
245
249
}
246
-
247
250
scope . $apply ( ) ;
248
251
} ) ;
249
252
0 commit comments