During the Peninsular War, when Spain had two rival Kings – the overthrown Bourbon Fernando VII and Napoleon's brother, Joseph Bonaparte, enthroned as José I of Spain – the United States officially maintained a neutral position between them. Ambassador Luis de Onís who arrived in New York in 1809, representing Fernando VII's government, was refused an audience to present his credentials to President James Madison. He was only recognized officially by the US government in 1815, following Napoleon's defeat – though in the meantime he had established himself in Philadelphia and unofficially conducted extensive diplomatic activity.