A very good idea is – if you have the time – to ask multiple taxi drivers for estimates of how much it will cost to get to your destination. If the estimates vary widely, you should be careful – very high estimates are obviously scams, but very low estimates may be tricks to get you into their cab, after which they’ll jack up the price. If you’re at an airport or some other central travel hub, you could also ask a local employee there how much a taxi ride to your destination should cost. However, beware that any local employees may be in league with taxi scammers! If you can find somebody from your country who’s familiar with the area, you should ask them how much your taxi fare should come to, as they are much less likely to be in league with taxi scammers.
Another good strategy is to only use taxis from larger corporations. Call a taxi rather than taking the first one in the cab lane. Cabs from larger corporations will usually be cleaner and more organised, and if your driver attempts to scam you, you can report him to his employer. The employer, however, may not care.
You could also try looking poor, as taxi scammers will usually be less inclined to scam somebody who does not appear to have any money. However, they may decide to scam you anyway because you do not likely have any significant influence with anyone who could punish them.
Another thing to try is phrasing your question as “Will $20 get me to the hotel?” so the amount of payment is established upfront. Even if you pay more than it would have taken to pay the fare, you limit your losses to the scammer.