|
@@ -297,11 +297,9 @@ public class GpsServiceImpl implements GpsService {
|
|
|
|
|
|
String currentStationId = null;
|
|
|
List<ShiftInfo> shiftInfoList = shiftInfoService.findByVehicleIdAndStatus(id, "1");
|
|
|
- if (shiftInfoList.size() > 0) {
|
|
|
-
|
|
|
|
|
|
+ if (shiftInfoList.size() > 0) {
|
|
|
ShiftInfo shiftInfo = shiftInfoList.get(0);
|
|
|
-
|
|
|
RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
|
|
|
|
|
|
List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeInfo.getId());
|
|
@@ -309,43 +307,74 @@ public class GpsServiceImpl implements GpsService {
|
|
|
|
|
|
//当前站点
|
|
|
StationInfo currentStation = stationInfoService.get(currentStationId);
|
|
|
+ int currentIndex = currentStation.getSortNo();
|
|
|
|
|
|
- int currentIndex = stationInfoList.indexOf(currentStation);
|
|
|
- //线路始站
|
|
|
- StationInfo startStation = stationInfoService.get(shiftInfo.getStartStationId());
|
|
|
//线路终点站
|
|
|
StationInfo endStation = stationInfoService.get(shiftInfo.getEndStationId());
|
|
|
|
|
|
+ boolean frontToEnd = true;
|
|
|
|
|
|
if (stationInfoList.size() > 0) {
|
|
|
- for (StationInfo stationInfo : stationInfoList) {
|
|
|
- GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
|
|
|
- GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(stationInfo.getLatitude()), Double.valueOf(stationInfo.getLongitude()));
|
|
|
-
|
|
|
- double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
|
|
|
- if (meter1 <= Double.valueOf(50)) {
|
|
|
- int indexStation = stationInfoList.indexOf(stationInfo);
|
|
|
- //线路的开始站是站点集合的第一个站点则是顺线路运行
|
|
|
- if (shiftInfo.getStartStationId().equals(stationInfoList.get(0).getId())){
|
|
|
- if (indexStation > currentIndex){
|
|
|
- currentStationId = stationInfo.getId();
|
|
|
- break;
|
|
|
- }
|
|
|
+ if(endStation.getId().equals(stationInfoList.get(0).getId())){
|
|
|
+ //反向行驶
|
|
|
+ frontToEnd = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(frontToEnd){
|
|
|
+ for (int i=0;i<stationInfoList.size();i++) {
|
|
|
+ StationInfo stationInfo = stationInfoList.get(i);
|
|
|
+
|
|
|
+ if(stationInfo.getSortNo() <= currentIndex){
|
|
|
+ //正向行驶时,排序比当前站小的站点不用计算
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (shiftInfo.getEndStationId().equals(stationInfoList.get(0).getId())){
|
|
|
- if (indexStation < currentIndex){
|
|
|
- currentStationId = stationInfo.getId();
|
|
|
- break;
|
|
|
- }
|
|
|
+
|
|
|
+ if(matchDistance(stationInfo,vehicleInfo,50)){
|
|
|
+ currentStationId = stationInfo.getId();
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ for (int i=stationInfoList.size() - 1;i>=0;i--) {
|
|
|
+ StationInfo stationInfo = stationInfoList.get(i);
|
|
|
|
|
|
+ if (stationInfo.getSortNo() >= currentIndex){
|
|
|
+ //反向行驶时,排序比当前站大的站点不用计算
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(matchDistance(stationInfo,vehicleInfo,50)){
|
|
|
+ currentStationId = stationInfo.getId();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return currentStationId;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询指定范围内的站点
|
|
|
+ * @param stationInfo
|
|
|
+ * @param vehicleInfo
|
|
|
+ * @param distance
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean matchDistance(StationInfo stationInfo,VehicleInfo vehicleInfo,int distance){
|
|
|
+ GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
|
|
|
+ GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(stationInfo.getLatitude()), Double.valueOf(stationInfo.getLongitude()));
|
|
|
+
|
|
|
+ double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
|
|
|
+
|
|
|
+ if (meter1 <= Double.valueOf(distance)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public String encode(String text) {
|
|
|
try {
|
|
|
text = URLEncoder.encode(text, "UTF-8");
|