| | |
| | | package com.xiaopeng.api.model.map; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; |
| | | import org.springframework.data.mongodb.core.index.CompoundIndex; |
| | | import org.springframework.data.mongodb.core.index.CompoundIndexes; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexType; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexed; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | |
| | | public class XpGeoFencingPolygon implements Serializable { |
| | | private static final long serialVersionUID = 4508868382007529971L; |
| | | |
| | | @Id |
| | | private String id; |
| | | |
| | | /** |
| | |
| | | package com.xiaopeng.api.model.map; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexType; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexed; |
| | |
| | | public class XpGeoFencingProhibitedPolygon implements Serializable { |
| | | private static final long serialVersionUID = 4508868382007529971L; |
| | | |
| | | @Id |
| | | private String id; |
| | | /** |
| | | * 围栏id |
| | |
| | | package com.xiaopeng.api.model.operation; |
| | | |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexType; |
| | | import org.springframework.data.mongodb.core.index.GeoSpatialIndexed; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | | import org.springframework.data.mongodb.core.mapping.Field; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | |
| | | * 地理位置(经纬度) |
| | | */ |
| | | @Field("location") |
| | | @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE) |
| | | private GeoJsonPoint location; |
| | | |
| | | /** |
| | |
| | | import com.xiaopeng.itinerary.repository.XpGeoQueryEntityRepository; |
| | | import com.xiaopeng.itinerary.service.IXpGeoQueryEntityService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.GeoResults; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.geo.*; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.NearQuery; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | |
| | | Long startTime = calendar.getTime().getTime(); |
| | | |
| | | // 1. 创建查询点 |
| | | Point referencePoint = new Point(longitude, latitude); |
| | | // Point referencePoint = new Point(longitude, latitude); |
| | | // |
| | | // // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | // NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | // .maxDistance(0.5) // 转成公里 |
| | | // .spherical(true); |
| | | // |
| | | // |
| | | // // 3.时间>startTime time = time参数 |
| | | // // 3. 创建额外的查询条件 |
| | | // Query query = new Query(); |
| | | // query.addCriteria(Criteria.where("timestamp").gte(startTime)); |
| | | // query.addCriteria(Criteria.where("time").is(time)); |
| | | // |
| | | // // 将 NearQuery 和额外的查询条件合并 |
| | | // nearQuery.query(query); |
| | | // |
| | | // |
| | | // // 4. 执行查询 - 明确指定集合名 |
| | | // GeoResults<XpGeoQueryEntity> geoResults = mongoTemplate.geoNear(nearQuery, XpGeoQueryEntity.class); |
| | | // |
| | | // // 5. 提取结果 |
| | | // return geoResults.getContent().stream() |
| | | // .map(geoResult -> geoResult.getContent()) |
| | | // .collect(Collectors.toList()); |
| | | |
| | | // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | .maxDistance(0.5) // 转成公里 |
| | | .spherical(true); |
| | | |
| | | |
| | | // 3.时间>startTime time = time参数 |
| | | // 3. 创建额外的查询条件 |
| | | Query query = new Query(); |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(longitude, latitude); |
| | | //构造半径 |
| | | Distance distanceR = new Distance(5, Metrics.KILOMETERS); |
| | | //画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | // 构造query对象 |
| | | Query query = Query.query(Criteria.where("location").withinSphere(circle)); |
| | | query.addCriteria(Criteria.where("timestamp").gte(startTime)); |
| | | query.addCriteria(Criteria.where("time").is(time)); |
| | | List<XpGeoQueryEntity> driverPositions = mongoTemplate.find(query, XpGeoQueryEntity.class); |
| | | |
| | | // 将 NearQuery 和额外的查询条件合并 |
| | | nearQuery.query(query); |
| | | |
| | | |
| | | // 4. 执行查询 - 明确指定集合名 |
| | | GeoResults<XpGeoQueryEntity> geoResults = mongoTemplate.geoNear( |
| | | nearQuery, |
| | | XpGeoQueryEntity.class, |
| | | "xp_geo_query_entity" // 明确指定集合名,避免映射错误 |
| | | ); |
| | | |
| | | // 5. 提取结果 |
| | | return geoResults.getContent().stream() |
| | | .map(geoResult -> geoResult.getContent()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return driverPositions; |
| | | } |
| | | |
| | | /** |
| | |
| | | import com.xiaopeng.itinerary.utils.XpPricingUtil; |
| | | import com.xiaopeng.itinerary.utils.holiday.HolidayUtil; |
| | | import com.xiaopeng.itinerary.utils.map.FastDistanceCalculator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * @author liu |
| | | * @since 2026-02-03 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class XpPricingServiceImpl extends ServiceImpl<XpPricingMapper, XpPricing> implements XpPricingService { |
| | | |
| | |
| | | xpOrder.setId(orderId); |
| | | // 静默处理 不推单 |
| | | if (isSilent) { |
| | | // todo 用于测试流程,正式联调需要删除此代码 |
| | | // testOrder(orderId); |
| | | log.info("订单取消次数达到上限,执行静默处理,不推单。"); |
| | | return orderId.toString(); |
| | | } |
| | | |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.bson.Document; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | private final XpGeoFencingPolygonService xpGeoFencingPolygonService; |
| | | private final RedisService redisService; |
| | | private final XpOrderClient xpOrderClient; |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | | public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient) { |
| | | public XpMapController(GDMapGeocodingUtil gdMapGeocodingUtil, XpGeoFencingPolygonService xpGeoFencingPolygonService, RedisService redisService, XpOrderClient xpOrderClient, MongoTemplate mongoTemplate) { |
| | | this.gdMapGeocodingUtil = gdMapGeocodingUtil; |
| | | this.xpGeoFencingPolygonService = xpGeoFencingPolygonService; |
| | | this.redisService = redisService; |
| | | this.xpOrderClient = xpOrderClient; |
| | | this.mongoTemplate = mongoTemplate; |
| | | } |
| | | |
| | | |
| | |
| | | // 获取电子围栏的禁行区域点位 |
| | | GeoPoint startPoint = new GeoPoint(dto.getOrigin().getLongitude(),dto.getOrigin().getLatitude()); |
| | | List<String> operatingArea = xpGeoFencingPolygonService.findFencesContainingPoint(startPoint, "operating_area", "points"); |
| | | String fenceId = operatingArea.get(0); |
| | | List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area"); |
| | | // 避让区域 |
| | | ArrayList<String> pointStrParam = new ArrayList<>(); |
| | | for (Document document : pointsInFence) { |
| | | List<GeoPoint> points = document.getList("points", GeoPoint.class); |
| | | // 一个区域的点位 |
| | | ArrayList<String> pointStr = new ArrayList<>(); |
| | | for (GeoPoint point : points) { |
| | | pointStr.add( point.getLongitude()+","+point.getLatitude()); |
| | | } |
| | | if(!pointStr.isEmpty()){ |
| | | pointStrParam.add(String.join(";", pointStr)); |
| | | String fenceId = null; |
| | | if(!operatingArea.isEmpty()){ |
| | | fenceId = operatingArea.get(0); |
| | | List<Document> pointsInFence = xpGeoFencingPolygonService.findPointsByParentId(fenceId, "parentId", "prohibited_area"); |
| | | for (Document document : pointsInFence) { |
| | | List<GeoPoint> points = document.getList("points", GeoPoint.class); |
| | | // 一个区域的点位 |
| | | ArrayList<String> pointStr = new ArrayList<>(); |
| | | for (GeoPoint point : points) { |
| | | pointStr.add( point.getLongitude()+","+point.getLatitude()); |
| | | } |
| | | if(!pointStr.isEmpty()){ |
| | | pointStrParam.add(String.join(";", pointStr)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | RouteVo routeVo = gdMapGeocodingUtil.getDistanceAndTime(dto.getOrigin(), dto.getDestination(), String.join("|", pointStrParam), fenceId,dto.getRoutePlanRule()); |
| | | if(routeVo==null){ |
| | | return R.fail("没有找到路线"); |
| | |
| | | import com.xiaopeng.map.utils.holiday.HolidayUtil; |
| | | import com.xiaopeng.map.vo.IsInOperationAreaVo; |
| | | import com.xiaopeng.map.vo.WalkTimeVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private HolidayUtil holidayUtil; |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<XpElectronicFenceVo> citiesList(String cityCode) { |
| | | List<XpGeoFencingPolygon> xpGeoFencingPolygons = xpGeoFencingPolygonService.findAll(); |
| | | List<XpGeoFencingPolygon> xpGeoFencingPolygons = mongoTemplate.find(new Query(Criteria.where("cityCode").is(cityCode)), XpGeoFencingPolygon.class); |
| | | if(xpGeoFencingPolygons.isEmpty()){ |
| | | return new ArrayList<>(); |
| | | } |
| | | xpGeoFencingPolygons = xpGeoFencingPolygons.stream().filter(e->e.getCityCode()!=null && e.getCityCode().equals(cityCode)).collect(Collectors.toList()); |
| | | List<XpElectronicFenceVo> result = new ArrayList<>(); |
| | | List<String> fenceIds = xpGeoFencingPolygons.stream().map(XpGeoFencingPolygon::getFenceId).collect(Collectors.toList()); |
| | | if(fenceIds.isEmpty()){ |
| | |
| | | } |
| | | } |
| | | |
| | | if (xpElectronicFence.getStatus() == 2) { |
| | | if (xpElectronicFence.getStatus() == 1 || xpElectronicFence.getStatus() == 2) { |
| | | for (XpElectronicFenceArea newElectronicFenceArea : newElectronicFenceAreas) { |
| | | if (newElectronicFenceArea.getAreaType() == 1 |
| | | && newElectronicFenceArea.getAreaStatus() == 1) { |
| | |
| | | // 删除旧的区域数据,然后保存新的区域数据 |
| | | xpElectronicFenceAreaMapper.delete(new LambdaQueryWrapper<XpElectronicFenceArea>() |
| | | .eq(XpElectronicFenceArea::getElectronicId, dto.getId())); |
| | | mongoTemplate.remove(new Query(Criteria.where("fenceId").is(String.valueOf(dto.getId()))), XpGeoFencingPolygon.class); |
| | | |
| | | if (xpElectronicFence.getStatus() == 2) { |
| | | // 设置电子围栏ID并保存区域数据 |
| | | for (XpElectronicFenceArea area : updatedElectronicFenceAreas) { |
| | |
| | | xpElectronicFenceAreaMapper.insert(area); |
| | | } |
| | | } |
| | | if (dto.getStatus() == 2) { |
| | | if (dto.getStatus() == 1 || dto.getStatus() == 2) { |
| | | for (XpElectronicFenceArea newElectronicFenceArea : updatedElectronicFenceAreas) { |
| | | if (newElectronicFenceArea.getAreaType() == 1 |
| | | && newElectronicFenceArea.getAreaStatus() == 1) { |
| | |
| | | XpGeoFencingPolygon xpGeoFencingPolygon = new XpGeoFencingPolygon(); |
| | | xpGeoFencingPolygon.setFenceId(String.valueOf(xpElectronicFence.getId())); |
| | | xpGeoFencingPolygon.setName(xpElectronicFence.getElectronicName()); |
| | | xpGeoFencingPolygon.setCityCode(cityCode); |
| | | xpGeoFencingPolygon.setAreaId(String.valueOf(newElectronicFenceArea.getId())); |
| | | xpGeoFencingPolygon.setOperationStrategy(xpElectronicFence.getOperationStrategy()); |
| | | // 将围栏点转换为GeoJSON多边形 |
| | | GeoJsonPolygon geoJsonPolygon = convertToGeoJsonPolygon(newElectronicFenceArea.getFencePoints()); |
| | | xpGeoFencingPolygon.setPoints(geoJsonPolygon); |
| | | mongoTemplate.insert(xpGeoFencingPolygon); |
| | | mongoTemplate.save(xpGeoFencingPolygon); |
| | | } else { |
| | | // 如果存在,则更新已有文档 |
| | | old.setFenceId(String.valueOf(xpElectronicFence.getId())); |
| | | old.setName(xpElectronicFence.getElectronicName()); |
| | | old.setCityCode(cityCode); |
| | | old.setAreaId(String.valueOf(newElectronicFenceArea.getId())); |
| | | old.setOperationStrategy(xpElectronicFence.getOperationStrategy()); |
| | | // 将围栏点转换为GeoJSON多边形 |
| | |
| | | package com.xiaopeng.map.vo; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | public class XpGeoPointPolygon implements Serializable { |
| | | private static final long serialVersionUID = 4508868382007529971L; |
| | | |
| | | @Id |
| | | private String id; |
| | | /** |
| | | * 围栏id |
| | |
| | | } |
| | | } |
| | | |
| | | if (xpElectronicFence.getStatus() == 2) { |
| | | if (xpElectronicFence.getStatus() == 1 || xpElectronicFence.getStatus() == 2) { |
| | | for (XpElectronicFenceArea newElectronicFenceArea : newElectronicFenceAreas) { |
| | | if (newElectronicFenceArea.getAreaType() == 1 |
| | | && newElectronicFenceArea.getAreaStatus() == 1) { |
| | |
| | | xpElectronicFenceAreaMapper.insert(area); |
| | | } |
| | | } |
| | | if (dto.getStatus() == 2) { |
| | | if (dto.getStatus() == 1 || dto.getStatus() == 2) { |
| | | for (XpElectronicFenceArea newElectronicFenceArea : updatedElectronicFenceAreas) { |
| | | if (newElectronicFenceArea.getAreaType() == 1 |
| | | && newElectronicFenceArea.getAreaStatus() == 1) { |
| | |
| | | import com.xiaopeng.operation.repository.XpGeoQueryEntityRepository; |
| | | import com.xiaopeng.operation.service.IXpGeoQueryEntityService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Distance; |
| | | import org.springframework.data.geo.GeoResults; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.geo.*; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.NearQuery; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | |
| | | calendar.add(Calendar.DAY_OF_YEAR, -7); |
| | | Long startTime = calendar.getTime().getTime(); |
| | | |
| | | // 1. 创建查询点 |
| | | Point referencePoint = new Point(longitude, latitude); |
| | | |
| | | // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | .maxDistance(0.5) // 转成公里 |
| | | .spherical(true); |
| | | |
| | | |
| | | // 3.时间>startTime time = time参数 |
| | | // 3. 创建额外的查询条件 |
| | | Query query = new Query(); |
| | | // // 1. 创建查询点 |
| | | // Point referencePoint = new Point(longitude, latitude); |
| | | // |
| | | // // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | // NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | // .maxDistance(0.5) // 转成公里 |
| | | // .spherical(true); |
| | | // |
| | | // |
| | | // // 3.时间>startTime time = time参数 |
| | | // // 3. 创建额外的查询条件 |
| | | // Query query = new Query(); |
| | | // query.addCriteria(Criteria.where("timestamp").gte(startTime)); |
| | | // query.addCriteria(Criteria.where("time").is(time)); |
| | | // |
| | | // // 将 NearQuery 和额外的查询条件合并 |
| | | // nearQuery.query(query); |
| | | // |
| | | // |
| | | // // 4. 执行查询 - 明确指定集合名 |
| | | // GeoResults<XpGeoQueryEntity> geoResults = mongoTemplate.geoNear( |
| | | // nearQuery, |
| | | // XpGeoQueryEntity.class, |
| | | // "xp_geo_query_entity" // 明确指定集合名,避免映射错误 |
| | | // ); |
| | | // |
| | | // // 5. 提取结果 |
| | | // return geoResults.getContent().stream() |
| | | // .map(geoResult -> geoResult.getContent()) |
| | | // .collect(Collectors.toList()); |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(longitude, latitude); |
| | | //构造半径 |
| | | Distance distanceR = new Distance(0.5, Metrics.KILOMETERS); |
| | | //画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | // 构造query对象 |
| | | Query query = Query.query(Criteria.where("location").withinSphere(circle)); |
| | | query.addCriteria(Criteria.where("timestamp").gte(startTime)); |
| | | query.addCriteria(Criteria.where("time").is(time)); |
| | | |
| | | // 将 NearQuery 和额外的查询条件合并 |
| | | nearQuery.query(query); |
| | | |
| | | |
| | | // 4. 执行查询 - 明确指定集合名 |
| | | GeoResults<XpGeoQueryEntity> geoResults = mongoTemplate.geoNear( |
| | | nearQuery, |
| | | XpGeoQueryEntity.class, |
| | | "xp_geo_query_entity" // 明确指定集合名,避免映射错误 |
| | | ); |
| | | |
| | | // 5. 提取结果 |
| | | return geoResults.getContent().stream() |
| | | .map(geoResult -> geoResult.getContent()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<XpGeoQueryEntity> xpGeoQueryEntities = mongoTemplate.find(query, XpGeoQueryEntity.class); |
| | | return xpGeoQueryEntities; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | import com.xiaopeng.api.vo.automaticPilot.VehiclePosition; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.geo.GeoResults; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.geo.Distance; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.*; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.NearQuery; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | |
| | | double latitude, |
| | | double distanceInMeters,int num) { |
| | | try { |
| | | // 1. 创建查询点 |
| | | Point referencePoint = new Point(longitude, latitude); |
| | | // // 1. 创建查询点 |
| | | // Point referencePoint = new Point(longitude, latitude); |
| | | // |
| | | // // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | // NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | // .maxDistance(distanceInMeters / 1000) // 转成公里 |
| | | // .spherical(true); |
| | | // |
| | | // |
| | | // // 4. 执行查询 - 明确指定集合名 |
| | | // GeoResults<VehiclePosition> geoResults = mongoTemplate.geoNear( |
| | | // nearQuery, |
| | | // VehiclePosition.class, |
| | | // "vehicle_position" // 明确指定集合名,避免映射错误 |
| | | // ); |
| | | // |
| | | // // 5. 提取结果 |
| | | // return geoResults.getContent().stream() |
| | | // .map(geoResult -> geoResult.getContent()) |
| | | // .collect(Collectors.toList()); |
| | | |
| | | // 2. 构建 NearQuery - 完全使用 NearQuery 的 API |
| | | NearQuery nearQuery = NearQuery.near(referencePoint, Metrics.KILOMETERS) |
| | | .maxDistance(distanceInMeters / 1000) // 转成公里 |
| | | .spherical(true); |
| | | |
| | | |
| | | // 4. 执行查询 - 明确指定集合名 |
| | | GeoResults<VehiclePosition> geoResults = mongoTemplate.geoNear( |
| | | nearQuery, |
| | | VehiclePosition.class, |
| | | "vehicle_position" // 明确指定集合名,避免映射错误 |
| | | ); |
| | | |
| | | // 5. 提取结果 |
| | | return geoResults.getContent().stream() |
| | | .map(geoResult -> geoResult.getContent()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(longitude, latitude); |
| | | //构造半径 |
| | | Distance distanceR = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); |
| | | //画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | // 构造query对象 |
| | | Query query = Query.query(Criteria.where("point").withinSphere(circle)); |
| | | List<VehiclePosition> vehiclePositions = mongoTemplate.find(query, VehiclePosition.class); |
| | | return vehiclePositions; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new ArrayList<>(); |