Sounds to me like he's trying to get your attention when you're out with him. If he only does it when you're there, and talking with other moms, he is probably seeking attention and negative attention is the fastest recourse. You're spanking, yelling, time outs, etc, are just the immediate attention he wants. Try this: When he acts badly, look away from his eyes, pick him up under his arms like a hot potato facing away from you, don't speak to him except maybe a quick, "You need to calm down. It's time for some time out." But make it very short. Then put him in his car seat or stroller and sit in the front seat of the car or on an isolated bench somewhere with the stroller next to you but facing away from you and read a book or something facing away from him. Try very hard not to show any emotion - this way he cannot feel as if he is in control of you because he is receiving the reaction he expects from his behavior - just disconnect until he works out his tantrum. Then, when he is done, praise him on how calm he is. "Look at you! You're not kicking! You're still! That's wonderful! Good job!" That sort of thing. This is based on parent-child attachment theory. It sends a very clear message to the child that his behavior will not be rewarded in a way that even a two year old can understand. He will take these lessons throughout his life. The important thing is to reconnect afterwards. Then maybe you could go back out and talk to your friends and try again after a few minutes - or an hour - depending on his mood. You could also try, "I can't let you play on the slide if you make the other kids sad so, if you act like that, we'll have to sit in the car. Now, if you'd like to spend your play time in the car with mommy, that's allright with me. I've brought a great book and will be fine here. But you might want to try behaving so you can play on the slide. But it's up to you. I'm good either way." This is called 'love and logic' parenting and gives the child control and makes him accountable for his own actions. I have found a combination of these techniques to be invaluable. The key is to talk as little as possible. Just let the actions do the talking. I tell my 2 year old, "Please don't yell at me. I'd be happy to listen when you can talk to me in a calm voice like mommy's. But until you can stop yelling and crying, I'm going to do [whatever] over here." Now, he turns 3 next week so he may be a bit older, but it's amazing how he can stop himself from crying and getting upset - calm himself down - and try to talk without whining and crying to communicate with me. Not every time, of course, but enough that I'm impressed with how much kids can learn at such a young age.
Best of luck! Try reading 'Love and Logic' parenting books or 'The Child Connection'. I've found these REALLY helpful!