Preheat the oven to 350°F (175°C). Grease a 9-inch (23cm) cake pan with butter and set aside. In a medium bowl, whisk together the flour, baking powder, baking soda, salt, cinnamon, and nutmeg. In a separate large bowl, beat the butter and sugar together until light and fluffy. Add the eggs, one at a time, and beat well after each addition. Gradually stir in the flour mixture, alternating with the milk, until the batter is smooth. Fold in the chopped apples and walnuts, if using. Pour the batter into the prepared cake pan and smooth the top with a spatula. In a small bowl, mix together the melted butter, sugar, and cinnamon for the topping. Drizzle the topping evenly over the cake batter. Bake for 50 to 55 minutes, or until a toothpick inserted into the center of the cake comes out clean. Let the cake cool in the pan for 10 minutes, then remove it from the pan and transfer it to a wire rack to cool completely. Slice and serve the apple cake as desired, perhaps with a dollop of whipped cream or a scoop of vanilla ice cream.