Reputation: 483
When I set the session variable using
Session.set('location',position);
After its set, when I try
Session.get('location')
through console, I get an empty object
I have even added session using
meteor add session
meteor add constellation:session
But still it does not give any value even after it sets its value
I have used it like:
Meteor.startup(function () {
navigator.geolocation.getCurrentPosition(successCallbk);
});
successCallbk = function(position) {
Session.set('location',position);
};
the position param received within successCallbk method, has a valid value, but that does not get retained in the location session var
Upvotes: 1
Views: 73
Reputation: 89
I know its a very long time since you posted this question but I decided since I was using Josh's videos for references with Meteor, I'd post my solution:
success = function(position) {
Session.set('location', {
'coords': {
'accuracy': position.coords.accuracy,
'latitude': position.coords.latitude,
'longitude': position.coords.longitude
},
'timestamp': position.timestamp
});
}
Basically, I just copied the objects values that were important to me from the position object. It works as expected now. For Reference: https://www.youtube.com/watch?v=7iqdkVwtuvg
Upvotes: 0
Reputation: 43
Try hardcoding it first.
Session.set('testSession', 'This is a test')
Setup the Session.Get for your template.
See if you can get it to display in a template. Go into the browser console and set the session to something else and see if it works.
If this works you may have to give us more code to look over.
Upvotes: 1
Reputation: 548
Session provides a global object on the client that you can use to store an arbitrary set of key-value pairs. Use it to store things like the currently selected item in a list.
You should try verify if you are on the client side:
if (Meteor.isClient) {
Meteor.startup(function () {
navigator.geolocation.getCurrentPosition(successCallbk);
});
successCallbk = function(position) {
Session.set('location',position);
};
};
Upvotes: 0