|
@@ -0,0 +1,29 @@
|
|
|
+package com.zswl.cloud.springBtach.server.core.dao.Impl;
|
|
|
+
|
|
|
+import com.zswl.cloud.springBtach.server.core.dao.extend.XiaoJuStoreDaoExtend;
|
|
|
+import com.zswl.cloud.springBtach.server.core.domain.XiaoJuStore;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.geo.*;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.query.NearQuery;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class XiaoJuStoreDaoImpl implements XiaoJuStoreDaoExtend{
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ public List<XiaoJuStore> findNearbyTargets(double longitude, double latitude, double maxDistanceInKilometers) {
|
|
|
+ Point point = new Point(longitude, latitude);
|
|
|
+ NearQuery query = NearQuery.near(point).maxDistance(new Distance(maxDistanceInKilometers, Metrics.KILOMETERS));
|
|
|
+ GeoResults<XiaoJuStore> results = mongoTemplate.geoNear(query, XiaoJuStore.class);
|
|
|
+ List<XiaoJuStore> nearbyTargets = new ArrayList<>();
|
|
|
+ for (GeoResult<XiaoJuStore> result : results) {
|
|
|
+ nearbyTargets.add(result.getContent());
|
|
|
+ }
|
|
|
+ return nearbyTargets;
|
|
|
+ }
|
|
|
+}
|