"America had endured British armies marauding around the country during the War of Independence and still prevailed and the British victory in capturing Washington had failed to end the war"
As to the question of whether or not is was a defeat, for America it was certainly a disaster. Although Madison consistently ranks as a middling to better than average President overall, his decision to promote the war is regularly cited as one of the worst political decisions ever.
One review by a panel of presidential scholars put Madison’s war high on the list of blunders being placed at number six. This puts it in the same league as Jefferson’s Embargo Act of 1807, not as bad as Watergate but worse than the Bay of Pigs. As a Founding Father Madison’s place is secure in history, being the major author of the Constitution and a significant to the Federalist Papers. As an effective politician he never found the means to bring his capabilities to bear, as one contemporary noted : “although this gentleman is a clever man he is very little acquainted with the world.”
To judge whether it was a defeat of not, we need to look at the aims the war attempted to achieve, or what it is reasonable to accept given our knowledge and hindsight. Despite endless speculation, it is not unreasonable to accept that America’s fourth president and a Founding Father was basically telling the truth about his objectives (see “Why America Attacked”). In addition there is significant evidence to believe that a further opportunistic war aim existed which was of forcing regime change in Canada from Imperial Loyalist to at least neutral. Based on these, it is very difficult to portray the outcomes as anything other than failure on all points. A reasonable test is to ask how the outcome would have been accepted at the outset. By this test, had the final accepted peace terms been suggested as a possible outcome before the war was declared it would have been branded a shameful retreat from principle.
To be specific, the American delegates to the peace negotiations in Ghent gave way on all points settling for the “status quo ante” or the situation before the declaration of war in the first place The British Empire made no concessions to American neutrality, the conflict with the Native Americans would increase to the point of virtual genocide through the rest of the century and Canada remained both intact and loyal to the Empire.
To take a step back and look at the impact of the war on American sovereignty in terms of international status and trade, it is easy to make a case that America rapidly surrendered to the power of explosive British capitalism and became to a large extent an economic colony whose major economic initiatives were around defensive tariffs rather than development. The war of 1812 did nothing to free America for the situation faced in the 1790’s with three quarters of all revenue to the US Treasury being dependent on commerce with Great Britain. Just as the Louisiana Purchase was dependant on a loan from London’s Barings Bank It was still possible for leading American financiers to say at the end of the 19th century that the paramount goal of the American economy was to keep the confidence of British investors who owned much of America. 
Another way to measure success is to look at the issue of whether America could have kept on fighting. Most historians and military strategists would accept that Prussian soldier and thinker von Clausewitz defined this question and its answer most clearly in his seminal work “On War”. (Although the thinking of Clausewitz more than stands the test of time, there is some value in reading modern military perspectives of his work such as “The Utility of Force” by General Rupert Smith.)
From a Clausewitz perspective, a country needs three things to be to maintain the ability to wage war:
Taken individually, the American ability to wage war by the end of the conflict was weak to the point of collapse. Those parts of the American navy which could evade the blockading British we simply too few and too small to operate as a force capable of inflicting strategic meaningful damage to their enemy. Raiding enemy shipping is good for morale at home, but does little to impact the outcome of a conflict. Individual American “raiders” could attack British merchant ships and occasional military vessels, but this in no way impacted their enemy’s ability to both fight and trade. America ships were in many cases literally rotting at their berths while British blockaders sat, sometimes in view of the harbor, waiting to pounce. With the repeated failures of the American land forces to invade Canada, it can be fairly stated that in military terms the United States had lost the capability to take the war to their enemy. They could certainly defend against the large scale raids both British such as New Orleans and Baltimore, but these raids in themselves would have had little strategic value even if they had succeeded. America had endured British armies marauding around the country during the War of Independence and still prevailed and the British victory in capturing Washington had failed to end the war
Limited to defense and lacking the capability to make any military moves which could actually end the war successfully and with an almost complete lack of other access to other resources such as borrowing to pursue their war aims, the government in Washington was faced with the dismal choice of continuing an unwinnable war it could not keep financing or surrender on the points which it went to war on in the first place.
In terms of leadership, the fact that President Madison began to seek for a negotiated settlement so soon after the start of the hostilities argues that the desire for sustained war was not deep and that the peace faction continued to gather strength. The desire for peace was influenced not only by the vague benefits of any victory, but by the horrendous cost to the voting people of keeping the war going.
The American economy was disintegrating to the point where it suffered an almost complete currency collapse and the Madison government was faced with the one of Jeffersonian America’s biggest U turns with the re-establishment of a central bank. Although only a minority of the population had a vote, there was still enough land owning white men suffering from the war to make the political elite nervous for their future.
Public support had always been questionable to the point where many could reasonably claim not to understand why the war was being fought. As was noted in the Congressional record during the final days of peace: “Mr. Milnor presented petitions from sundry inhabitants of the city and county of Philadelphia and the county of Delaware in the State of Pennsylvania, stating their firm and unqualified conviction that the United States are not impelled to war against Great Britain by necessity, nor invited to it by expediency.”
Given this lack of popular support for the war, the lack of unequivocal leadership commitment to victory even from those such as Madison who decided to wage it initially, the collapse of America’s economic ability to continue to provide resources to the armed forces and the enforced defensive nature of the American military it is impossible to characterize the strategic position of the USA as being anything but defeated.
 Chernow p294.
 Chernow p 341.
 The House of Morgan, Ron Chernow, Simon and Schuster 1990.p25
 House of Morgan, Ron Chernow p41
 “The Utility of Force”, General Rupert Smith.
 A Century of Lawmaking for a new nation. US Congressional documents and debates 1774-1875.