mobile-packages icon indicating copy to clipboard operation
mobile-packages copied to clipboard

When does the Geolocation become available?

Open brylie opened this issue 11 years ago • 7 comments

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?

brylie avatar Jan 21 '15 14:01 brylie

I have tried calling Geolocation.latLng() from within Meteor.startup(), but get the error Geolocation is not defined

brylie avatar Jan 21 '15 16:01 brylie

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.

stubailo avatar Jan 21 '15 18:01 stubailo

I am trying to pass the geolocation as an argument to my subscription function. E.g.

var geolocation = Geolocation.latLng();
Meteor.subscribe('subscription', geolocation);

brylie avatar Jan 21 '15 21:01 brylie

We also noticed that the first time Geolocation.latLng() is called, nothing returns. Is this documented?

brylie avatar Jan 27 '15 09:01 brylie

It sometimes returns nothing when the geolocation system is not ready.

stubailo avatar Jan 27 '15 16:01 stubailo

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 }); };

tekknikk avatar Jan 27 '15 17:01 tekknikk

Thanks for the example @tekknikk. I will try it on our app.

brylie avatar Jan 28 '15 15:01 brylie