Guest User

Untitled

a guest
May 20th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. @Document(collection = "zones")
  2. public class Zone implements Identifiable<String> {
  3. ... (other fields)
  4. private GeoJsonPoint location;
  5. ... (getters/setters)
  6. }
  7.  
  8. @Repository
  9. public interface ZoneRepository extends CrudRepository<Zone, String> {
  10.  
  11. List<Zone> findByLocationNear(Point p, Distance d);
  12.  
  13. }
  14.  
  15. ...
  16. Point p = new GeoJsonPoint(Double.valueOf(longitude), Double.valueOf(latitude));
  17. Distance d = new Distance(distance, Metrics.KILOMETERS);
  18. return zoneRepository.findByLocationNear(p, d);
  19.  
  20. db.zones.find( { "location" :
  21. { $near :
  22. { $geometry : { type : "Point" , coordinates : [-82.706480, 28.038458]},
  23. $maxDistance : 50
  24. } } } )
  25.  
  26. {
  27. "_id" : ObjectId("12341983471693746"),
  28. "name" : "Some location",
  29. "location" : {
  30. "type" : "Point",
  31. "coordinates" : [
  32. -82.706480,
  33. 28.038458
  34. ]
  35. },
  36. }
Add Comment
Please, Sign In to add comment