title: how store latitude and longitude in mongodb collection? and How to use it with Spring?
body: <p>i want to find near by location so inserting record like this..</p>
  
  <pre><code>db.locationcol.insert({"location":"phase 8,mohali ,punjab ,india","service":"psychologist","loc":{"lon":76.703347,"lat":30.710459}})
  </code></pre>
  
  <p>and then executing Query on terminal .</p>
  
  <pre><code>db.runCommand(
  {
  geoNear: "locationcol",
  near: { type: "Point", coordinates: [ 76.720845, 30.712097 ] },
  spherical: true,
  query: { category: "public" }
  })
  </code></pre>
  
  <p>but it is returning ..</p>
  
  <pre><code>{ "ok" : 0, "errmsg" : "no geo indices for geoNear" }
  </code></pre>
  
  <p>i am also trying it with Spring ...</p>
  
  <pre><code>public GeoResults getnearby(double longitude,double latitude, String service) {
  
  Point point = new Point(longitude,latitude);
  
  Query query = new Query(Criteria.where("service").is(service));
  
  query.fields().include("service").include("location").include("loc");
  
  NearQuery nearQuery = NearQuery.near(point).maxDistance(new Distance(50, Metrics.KILOMETERS));
  nearQuery.query(query);
  nearQuery.num(20);
  
  GeoResults&lt;locationcol&gt; data = operations.geoNear(nearQuery, locationcol.class,"locationcol");
  
  return data;
  }
  </code></pre>
  
  <p>this code is returning empty list .i am not getting that where i am going wrong. help !!</p>