Skip to content

Commit

Permalink
Get latest location in ApplicationController
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Oct 6, 2013
1 parent 2113f60 commit 4a1f119
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions www/index.html
Expand Up @@ -146,6 +146,7 @@ <h2>Access</h2>
<script src="js/application.js"></script>
<script src="js/router.js"></script>
<script src="js/models/campsite.js"></script>
<script src="js/controllers/application.js"></script>
<script src="js/controllers/campsites.js"></script>
<script src="js/views/map.js"></script>
</body>
Expand Down
11 changes: 11 additions & 0 deletions www/js/controllers/application.js
@@ -0,0 +1,11 @@
App.ApplicationController = Ember.Controller.extend({
updateLocation: function() {
// TODO really should wait for deviceready event before calling this
// document.addEventListener('deviceready', this.trulyUpdateLocation, false);
navigator.geolocation.getCurrentPosition(this.geoLocation, null, {enableHighAccuracy: true});
},
geoLocation: function(location){
Ember.set(App, 'latitude', location.coords.latitude);
Ember.set(App, 'longitude', location.coords.longitude);
}
});
12 changes: 1 addition & 11 deletions www/js/controllers/campsites.js
@@ -1,13 +1,3 @@
App.CampsitesController = Ember.ArrayController.extend({
sortProperties: ["distance"],

updateLocation: function() {
// TODO really should wait for deviceready event before calling this
// document.addEventListener('deviceready', this.trulyUpdateLocation, false);
navigator.geolocation.getCurrentPosition(this.geoLocation, null, {enableHighAccuracy: true});
},
geoLocation: function(location){
Ember.set(App, 'latitude', location.coords.latitude);
Ember.set(App, 'longitude', location.coords.longitude);
}
sortProperties: ["distance"]
});
7 changes: 3 additions & 4 deletions www/js/router.js
Expand Up @@ -19,6 +19,9 @@ App.ApplicationRoute = Ember.Route.extend({
store.pushMany('campsite', data);
}
});
},
setupController: function(controller, model) {
controller.updateLocation();
}
});

Expand All @@ -28,8 +31,4 @@ App.CampsitesRoute = Ember.Route.extend({
return campsite.get("hasCoordinates");
});
},
setupController: function(controller, model) {
controller.updateLocation();
controller.set('model', model);
}
});

0 comments on commit 4a1f119

Please sign in to comment.