Exemplo n.º 1
0
 private RestaurantFullInfo findRestaurantByDistance(
     CoordinatePosition userCoordinatePosition, Double currentDistance, Boolean isFarther) {
   List<RestaurantFullInfo> restaurantFullInfoList = restaurantDAO.getAllRestaurantInfo();
   Double minDistance = Double.MAX_VALUE;
   RestaurantFullInfo selectedRestaurantFullInfo = null;
   for (RestaurantFullInfo restaurantFullInfo : restaurantFullInfoList) {
     Double restaurantDistance =
         MathUtils.getDistance(userCoordinatePosition, restaurantFullInfo.getCoordinatePosition());
     if ((isFarther
             && restaurantDistance > currentDistance
             && restaurantDistance < (currentDistance + minDistance))
         || (!isFarther
             && restaurantDistance < currentDistance
             && restaurantDistance > (currentDistance - minDistance))) {
       selectedRestaurantFullInfo = restaurantFullInfo;
       minDistance = Math.abs(restaurantDistance - currentDistance);
     }
   }
   return selectedRestaurantFullInfo;
 }
Exemplo n.º 2
0
  @Override
  public TableInfo getNewRestaurant(RestaurantSelectParam restaurantSelectParam) {
    CoordinatePosition userCoordinatePosition = new CoordinatePosition();
    userCoordinatePosition.setLongitudeValue(restaurantSelectParam.getUserLongitude());
    userCoordinatePosition.setLatitudeValue(restaurantSelectParam.getUserLatitude());
    CoordinatePosition currentTableCoordinatePosition =
        tableService.getTableCoordinatePosition(restaurantSelectParam.getTableId());
    Double currentDistance =
        MathUtils.getDistance(userCoordinatePosition, currentTableCoordinatePosition);

    TableInfo tableInfo =
        getNewRestaurant(
            userCoordinatePosition, currentDistance, restaurantSelectParam.getIsFarther());
    if (tableInfo != null) {
      return tableInfo;
    } else {
      // todo 提示用户信息
      return tableService.getTableInfo(restaurantSelectParam.getTableId());
    }
  }