司机端的小程序可以实时上传定位坐标,并且Redis中保存了司机的GEO缓存和上线缓存。创建订单的过程中,我们要查找附近适合接单的司机。如果有这样的司机,代驾系统才会创建订单,否则就拒绝创建订单。
既然要计算方圆几公里以内的司机,我们就得用上Redis的GEO计算,要写的代码如下。
@Service
public class DriverLocationServiceImpl implements DriverLocationService {
……
@Override
public ArrayList searchBefittingDriverAboutOrder(double startPlaceLatitude,
double startPlaceLongitude,
double endPlaceLatitude,
double endPlaceLongitude,
double mileage) {
//搜索订单起始点5公里以内的司机
Point point = new Point(startPlaceLongitude, startPlaceLatitude);
//设置GEO距离单位为千米
Metric metric = RedisGeoCommands.DistanceUnit.KILOMETERS;
Distance distance = new Distan