Sorry for the late reply.
Firstly there is a town called Espana :
http://maps.yahoo.com/#mvt=m&lat=40.62...=Espana%2C%20ESThat is not the only case, as there are a lot of towns that share their name with countries.
GeoPlanet by default always returns the single most likely place, so for "Espana", "Brazil" or "Australia" you will get a country:
http://where.yahooapis.com/v1/places.q(Esp...ppid=YOUR_APPIDIf you use a filter by type Town, like you did, GeoPlanet returns the most likely town, even though we are much more sure that "Espana" is usually a country. So what you need to do is not use a filter, and do the filtering yourself by looking at the "placeTypeName" result in the XML (or JSON).
For example, you will display Madrid because you have <placeTypeName code="7">Town</placeTypeName> in the XML:
http://where.yahooapis.com/v1/places.q(Mad...ppid=YOUR_APPIDI hope this helps,
Walter