【九月打卡】第17天 多端全棧項(xiàng)目實(shí)戰(zhàn)
標(biāo)簽:
SpringBoot
课程名称:多端全栈项目实战:商业级代驾全流程落地
课程章节: 华夏代驾全栈小程序实战
课程讲师: 神思者
课程内容:
前端实时上传gps定位
课程收获:
当上传了实时得定位坐标,并且在redis里面保存了司机得geo缓存和上线缓存,接下来就是创建订单业务,在创建订单得过程中,需要先查找附近适合接单得司机,如果有司机,代驾系统才去创建订单,否则就不创建。
因为要计算方圆几公里内得司机,我们就要用到redis 得 geo 计算
首先编写一个抽象方法
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 Distance(5, metric);
Circle circle = new Circle(point, distance);
//创建GEO参数
RedisGeoCommands.GeoRadiusCommandArgs args = RedisGeoCommands.GeoRadiusCommandArgs .newGeoRadiusArgs()
.includeDistance() //结果中包含距离
.includeCoordinates() //结果中包含坐标
.sortAscending(); //升序排列
//执行GEO计算,获得查询结果
GeoResults<RedisGeoCommands.GeoLocation<String>> radius = redisTemplate.opsForGeo()
.radius("driver_location", circle, args);查找司机是否在线
//排查掉不在线的司机
if (!redisTemplate.hasKey("driver_online#" + driverId)) {
continue;
}
//查找该司机的在线缓存
Object obj = redisTemplate.opsForValue().get("driver_online#" + driverId);
//如果查找的那一刻,缓存超时被置空,那么就忽略该司机
if (obj == null) {
continue;
}判断两次是因为 上一秒还在 但马上下线得情况
判断是否符合接单范围
//判断订单里程是否符合
boolean bool_2 = false;
if (orderDistance == 0) {
bool_2 = true;
} else if (orderDistance == 5 && mileage > 0 && mileage <= 5) {
bool_2 = true;
} else if (orderDistance == 10 && mileage > 5 && mileage <= 10) {
bool_2 = true;
} else if (orderDistance == 15 && mileage > 10 && mileage <= 15) {
bool_2 = true;
} else if (orderDistance == 30 && mileage > 15 && mileage <= 30) {
bool_2 = true;
}判断订单和司机定向是否符合
//判断定向接单是否符合
boolean bool_3 = false;
if (!orientation.equals("none")) {
double orientationLatitude = Double.parseDouble(orientation.split(",")[0]);
double orientationLongitude = Double.parseDouble(orientation.split(",")[1]);
//把定向点的火星坐标转换成GPS坐标
double[] location = CoordinateTransform.transformGCJ02ToWGS84(orientationLongitude, orientationLatitude);
GlobalCoordinates point_1 = new GlobalCoordinates(location[1], location[0]);
//把订单终点的火星坐标转换成GPS坐标
location = CoordinateTransform.transformGCJ02ToWGS84(endPlaceLongitude, endPlaceLatitude);
GlobalCoordinates point_2 = new GlobalCoordinates(location[1], location[0]);
//这里不需要Redis的GEO计算,直接用封装函数计算两个GPS坐标之间的距离
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.WGS84, point_1, point_2);
//如果定向点距离订单终点距离在3公里以内,说明这个订单和司机定向点是顺路的
if (geoCurve.getEllipsoidalDistance() <= 3000) {
bool_3 = true;
}
} else {
bool_3 = true;
}
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫(xiě)下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦

