Short answer: it depends. With some location specific domains (like .ca), you actually have to live in or do business from Canada. Others, like .ly (Libya), are administered from within that country but can be bought and used by anyone. Still others, like .io, used to be location based (British Indian Ocean Territory), but aren’t anymore because some locations are just too small to really get their feet wet with loads of websites.
Some people choose to purchase those last two to create unique and memorable website names like ow.ly or lover.ly (shout out to the My Fair Lady reference!)
Those examples are all ccTLDs—they belong to specific countries. But that’s not your only option if you want to go location-based. You can also use a gTLD that names a place, like .london. Anyone can sign up for a gTLD.