实体类
/**
* 地理位置经纬度
*/
@GeoSpatialIndexed(type= GeoSpatialIndexType.GEO_2DSPHERE)
private BasicDBObject loc;
存入方式
BasicDBObject loc = new BasicDBObject();
loc.put("type", "Point");
loc.put("coordinates", new double[]{longitude, latitude});
- longitude:经度
- latitude:维度
数据库中的样子
"loc" : {
"type" : "Point",
"coordinates" : [
116.46061,
39.935078
]
},
聚合查询方式
Aggregation.geoNear(
NearQuery.near(107.628316, 27.645687)
.query(new Query())
.distanceMultiplier(6378100.0)
.spherical(true),
"dis"
)