When does the Geolocation become available?
I am writing an app using Geolocation, but having trouble accessing the Geolocation object. For example, I have tried to access Geolocation.latLng() in my subscriptions (to filter the data by geolocation), but it keeps returning null. When/where is the Geolocation object available?
I have tried calling Geolocation.latLng() from within Meteor.startup(), but get the error Geolocation is not defined
What do you mean by "in my subscriptions"? If you mean inside the publish function on the server, then Geolocation won't work because it's only available on the client.
I am trying to pass the geolocation as an argument to my subscription function. E.g.
var geolocation = Geolocation.latLng();
Meteor.subscribe('subscription', geolocation);
We also noticed that the first time Geolocation.latLng() is called, nothing returns. Is this documented?
It sometimes returns nothing when the geolocation system is not ready.
I used a ReactiveVar in a template.created callback like this:
Template.createStudent.created = function () { this.data.location = new ReactiveVar(Geolocation.latLng() || { lat: 0, lng: 0 }); };
Thanks for the example @tekknikk. I will try it on our app.