The Earth's geomagnetic field (GMF) is known to act as a sensory cue for magnetoreceptive animals such as birds, sea turtles, and butterflies in long-distance migration, as well as in flies, cockroaches, and cattle in short-distance movement or body alignment. Despite a wealth of information, the way that GMF components are used and the functional modality of the magnetic sense are not clear. A GMF component, declination, has never been proven to be a sensory cue in a defined biological context. Here, we show that declination acts as a compass for horizontal food foraging in fruit flies. In an open-field test, adopting the food conditioning paradigm, food-trained flies significantly orientated toward the food direction under ambient GMF and under eastward-turned magnetic field in the absence of other sensory cues. Moreover, a declination change within the natural range, by alteration only of either the east-west or north-south component of the GMF, produced significant orientation of the trained flies, indicating that they can detect and use the difference in these horizontal GMF components. This study proves that declination difference can be used for horizontal foraging, and suggests that flies have been evolutionarily adapted to incorporate a declination compass into their multimodal sensorimotor system.