Interplay of local structure, charge, and spin in bilayered manganese perovskites