Based on Beijing–Arizona–Taiwan–Connecticut (BATC) and Sloan Digital Sky Survey (SDSS) photometric data, we adopt the spectral energy distribution (SED) fitting method to evaluate the metallicity distribution for ∼40 000 main‐sequence stars in the Galaxy. According to the derived photometric metallicities of these sample stars, we find that the metallicity distribution shifts from metal‐rich to metal‐poor with the increase of distance from the Galactic Centre. The mean metallicity is about −1.5 ± 0.2 dex in the outer halo and −1.3 ± 0.1 dex in the inner halo and smoothly decreases from −0.4 to −0.8 in the interval 0 < r≤ 5 kpc. A fluctuation in mean metallicity with Galactic longitude can be found in the interval 4 < r≤ 8 kpc. There is a vertical abundance gradient d[Fe/H]/dz∼−0.21 ± 0.05 dex kpc−1 for the thin disc (z≤ 2 kpc). At a distance 2 < z≤ 5 kpc, where thick‐disc stars dominate, the gradient is about −0.16 ± 0.06 dex kpc−1; this can be interpreted as a mixture of stellar populations with different mean metallicities at all z levels. The vertical metallicity gradient is −0.05 ± 0.04 dex kpc−1 for the halo (z > 5 kpc), so there is little or no metallicity gradient in the halo.