Meteorological geolocation method from event
I want to get latLng, but only after the event. How can this be achieved? I tried tracker and the like, but nothing worked. The only thing that worked was the call to Geolocation.latLng (); from within the helper that is in front of the event.
This is how I want it to work. I've tried the same with Session.set () and Session.get ()). I also tried to use Tracker dependencies, but since the location is not available, immediately triggering the change () does not help.
I have to include that I am using a package created by the Meteor Development Group located at https://github.com/meteor/mobile-packages/ .
var location = {};
Template.Home.helpers({
'location': function() {
return location;
}
);
Template.Home.events({
'focus .location': function() {
location = Geolocation.latLng();
},
});
source to share
This is because yours is location
not the most reactive variable.
var location = new ReactiveVar();
Template.Home.helpers({
'location': function() {
return location.get();
}
);
Template.Home.events({
'focus .location': function() {
location.set(Geolocation.latLng());
},
});
Don't forget to include reactive package var
Meteor add reactive-var
But, since you are using mdg: geolocation
And here the API Doc says every method is reactive, you can use the tracker in onRendered
the callback regardless of location changes
Template.Home.onRendered(function(){
this.autorun(function(){
location.set(Geolocation.latLng());
})
});
source to share
I like @ ZuzEL's answer, but in case you really want to do it your way with Session:
Template.Home.helpers({
'location': function() {
return Session.get("location");
}
);
Template.Home.events({
'focus .location': function() {
Session.set("location", Geolocation.latLng());
},
});
no need for ReactiveVar package because sessions are like a global react :)
source to share