title: Publications Subscriptions Observe
body: <p>I am working on a project where I want to show markers on a map.</p>
  
  <p>These markers should be published from server with a viewport-constraint. That means that just markers are published which are inside the current users viewport.</p>
  
  <p>The publication looks something like this:</p>
  
  <pre><code>//server
  Meteor.publish('posts', function(bottom_left_x, bottom_left_y, upper_right_x, upper_right_y, limit) {
  
    return Posts.find({locs: {$geoWithin: {$box:
                                    [[bottom_left_x, bottom_left_y],
                                     [upper_right_x, upper_right_y]]}}},
                         {sort: {submitted: -1}, limit: limit});
  });
  </code></pre>
  
  <p>I always call this function via subscription when my map_center changes:</p>
  
  <pre><code>//client
  google.maps.event.addListener(map, 'idle', function(event) {
    var bounds = map.getBounds();
  
    var ne = bounds.getNorthEast();
    var sw = bounds.getSouthWest();
    postsHandle= Meteor.subscribe('posts', sw.lat(), sw.lng(), ne.lat(), ne.lng(), 10);
  });
  </code></pre>
  
  <p>Till now everything works fine.
  Further i created a observefunction on posts, that renders a marker when "added" is called and remove when "removed" is called. Observe is very good to render new markers and to destroy the old ones</p>
  
  <pre><code>//client
  Posts.find().observeChanges({
    added: function(post) {
    // when 'added' callback fires, add HTML element
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(post.locs.lat, post.locs.lng),
        postId: post._id,
        map: map,
      });
  },removed .... and so on
  </code></pre>
  
  <p>That problem is that the observe-Callback is triggered on the whole Posts-Collection. But  i just want to show markers which are inside the users viewport. Thats why i normally have to do something like this:</p>
  
  <pre><code>//client
  Posts.find({locs: {$geoWithin: {$box:
                                    [[bottom_left_x, bottom_left_y],
                                     [upper_right_x, upper_right_y]]}}},
                         {sort: {submitted: -1}, limit: limit}).observeChanges({
  </code></pre>
  
  <p>But thats not possible. GeoWithin is not supported inside minimongo and it is not possible to call oberserve with a collection that has a limit.</p>
  
  <p>Has anyone an idea how to accomplish this?
  Maybe there is a way to push the posts i get from subcription directly to the map without using a query on minimongo? </p>