Search code examples
javascriptmeteorgeolocationiron-router

Error: Did not check() all arguments during publisher


Im trying to display itemts within a distance (from user's location). Only the loading screen appears. Error message appears on the terminal (server).

Publish

  Meteor.publish('postsByDistance', function(currentLocation) { 
    return Posts.find({
      loc: { 
        $near: { 
        }...

Solution

  • You should check your arguments using check();. Take a look at the docs for check(). In your case you should test against an Object (considering that the Geolocation.latLng() function from the MDG package returns an Object)

    Meteor.publish('postsByDistance', function(currentLocation) { 
        check(currentLocation, Object);
        return Posts.find({
    ...
    ...
    

    Also an option

    check(currentLocation, Match.ObjectIncluding({lat: Number, lng: Number}))