ISTANBUL, Turkey — It’s probably a matter of geography. But the Turkish government has been masterful in recent years at keeping friends in both the Middle East and the West, despite all the conflicts in between.

Turkey has carefully calibrated relations with countries in its neighborhood — which include perennial thorns like Iran, Syria, Iraq and Russia — and with the United States, which is so engaged in the region some there feel they should be able to vote in the US presidential election.

Turkish Prime Minister Recep Tayyip Erdogan has sought to expand trade with its immediate neighbors, irking the West but never alienating it — no easy task.

But with the Arab Spring and the Syrian conflict, things are changing in the region, and it might be the administration of US President Barack Obama that wins out in the end.

Since Obama took office, relations with Turkey are perhaps the best they’ve ever been.

“Turkey-US relations reached almost its peak under Obama,” said Sinan Ulgen, chairman of the Center for Economic and Foreign Policy Studies, a think tank in Istanbul. “[It] is obviously the consequence of the Arab revolts where Turkey and the US are very much standing side by side.”

Turkey and the United States also both support the Syrian opposition. And there are other factors too. Tensions between Turkey and Iran recently heightened in part because of Iran’s support for the Syrian regime. Turkey had previously tried to engage Iran, worrying its NATO allies, including the United States.

“Now that’s over. Now Turkey’s relationship with Iran and a number of other countries in Turkey’s neighborhood is very different, much more antagonistic,” Ulgen said.

Turkey’s increasing alienation from Europe has also brought the importance of its alliance with the United States to the fore. “Europe’s ineffectiveness as a regional policy actor, bogged down and mired in its own economic crisis, in a way accentuates the role of the US for Turkey policymakers,” he said.

From the US perspective, Turkey’s importance as a regional ally has grown as the Arab Spring remakes the politics of the region. Egypt, for decades an all-important ally to the United States, for example, is now charting a new path that isn’t necessarily in its interests.

“[Obama] appreciated more the Turkish strength in dealing with the Middle East. So he wanted to benefit from that possibility that the influence of Turkey on that neighborhood may be useful for the American interests as well,” said Oktay Aksoy, a former Turkish ambassador now working for the Foreign Policy Institute in Ankara.

Things were not always so rosy. Turkey did not support the US invasion of Iraq and refused to let America use its territory to move troops. The United States responded by preventing Turkey from pursuing Kurdish independence fighters in Iraqi territory.

But Obama’s withdrawal from Iraq in 2011 made it possible to mend relations and again cooperate on foreign policy, according to Ilter Turan, a political science professor at the international relations department at Bilgi University in Istanbul.

According to media reports, Turkish soldiers are again in Iraq pursuing Kurdish militants, who seek to create an autonomous region in parts of Iraq, Turkey and Syria.

In a sign of improving relations between Turkey and the United States, in 2011 Turkey agreed to host a US early warning radar system. The radars are part of NATO’s larger missile defense system, created to counter ballistic missile threats from Iran.

Suat Kiniklioglu, a columnist for Today’s Zaman, wrote last September that a senior US administration official described it as one of the “biggest strategic decisions taken between Turkey and the United States in the last 15 to 20 years.”

The happy relationship, however, is tenuous at best. And it could be the issue of Syria that does it in.

Ulgen said Turkey is increasingly frustrated by the lack of US support for intervention in Syria. “The US has been reluctant to entertain Turkish demands for an outright intervention in Syria. That is one area which increasingly tends to fall outside the scope of this very good relationship.”

And for all the improvement in relations, many Turks aren’t buying it. Like many others in the region, they distrust the United States.

Only 15 percent of Turks have a favorable view of the United States, according to a poll by the Pew Research Center.

“If anything happens to Turkey, many people assume it is either an Israeli or American conspiracy,” said Mensur Akgun, director of the Global Political Trends Center in Istanbul.

Opposition politicians still find support by linking government policies to the United States. “They tend to believe, or present, the Turkish government policies as sort of being proxy to the US,” Akgun said.

There is little truth to that accusation, he added.

“Turkey has been pursuing a rather autonomous policy vis a vis many of these countries. Having joint or common interests doesn’t mean Turkey is behaving like a US proxy.”