There have been taxis in St Petersburg since 1906, and after the Russian Revolution in 1917, all taxis were confiscated for use by the Red Army and the government, with normal service only being resumed in 1929. After the collapse of the Soviet Union, a taxi driver was basically anyone who had a car and wanted to use it to make money, so official taxis were few and far between. These days, there are more licensed taxis and prices are more reasonable.
Having said this, unless you speak Russian, we wouldn't recommend flagging down a taxi on the street in St Petersburg, as drivers are unlikely to speak English. If you do decide to do this, bear in mind that the "taxis" are still not always official licensed vehicles, despite what the driver may say.
The best thing to do is book a taxi via a reliable service. Your accommodation will provide you with recommended numbers to call or contact them for you, or alternatively, the Yandex app is a really useful way to book taxis on the go. Like other taxi apps, you can select the exact pick up and drop off addresses, avoiding the language barrier as much as possible.
We always recommend agreeing the price of your taxi in advance, clearly indicating your destination, to avid misunderstandings and nasty surprises when it comes to paying.
Fees are generally reasonable, and often cheaper if booked in advance. Taxis to and from the airport usually cost around 1050 Roubles depending on the location of your hotel or drop off point.