MongoTemplate地理位置查询(标准)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jiangshuanshuan/article/details/84567070
@GeoSpatialIndexed(type=GeoSpatialIndexType.GEO_2DSPHERE)
private GeoJsonPoint loc;
//GeoJsonPoint loc = new GeoJsonPoint(lon, lat);
  1. 矩形查询
		Point bottomLeft = new Point(minLon, minLat);
		Point topRight = new Point(maxLon, maxLat);
		Box box = new Box(bottomLeft, topRight);
		Query query = new Query(Criteria.where("loc").within(box));
		return mongoTemplate.find(query, LonLat.class);
  1. 圆形查询(米)
      Point center = new Point(lon, lat);
      Circle circle = new Circle(center, new Distance(distance / 1000D, Metrics.KILOMETERS));
      query.addCriteria(Criteria.where("loc").withinSphere(circle));
      return mongoTemplate.find(query, LonLat.class);
  1. 最近点查询
		Point p = new Point(lon, lat);
		Query query = new Query(Criteria.where("loc").nearSphere(p));
		return mongoTemplate.find(query.limit(size), LonLat.class);
展开阅读全文

没有更多推荐了,返回首页