Oh boy, does this take me back to when my own son was that age !!
He is really playing a game with you !
As adults, we find it hard to believe that negative attention can be rewarding, but in a child's world, it certainly can be.
He is getting exactly what he wants when you leave where ever you are because of his behavior. He wants to leave ! And then, he has learned nothing about how to get what he wants appropriately, but only how to immediately get out of a situation he finds boring or uncomfortable !
Don't leave where you are, unless it is someplace HE really wants to be, like the toy store. Even then, try "time out" first. You can always find a corner somewhere, or if necessary, time out in your car. This will work better if you do this first ....
Before you go, have a talk with him. Even a two year old can understand a simple talk about what you expect from him, and the reward or punishment that will accompany his behavior. Tell him exactly what good behavior you want from him, and then explain what behavior you will not tolerate. Next tell him there will be a reward if he is good (reiterate the expected behavior at this point) and a punishment if he is naughty (reiterate the naughty behavior). Decide together before you leave what his reward and punishment will be. If you are going to the grocery store, it is easy to decide the reward when you arrive, as it won't be long before you hear him beg for something. If it is reasonable, you can use what ever he begged for as his reward.
Tell him "ok, if you are quiet, do not kick on the floor, and obey Mommy all through the store, then I will give you that as a reward AS SOON AS WE LEAVE this store."
As you walk the isles, take every opportunity to tell him what a good boy he is being, and remind him how nice it will be when he gets that reward, and how proud Gramma (or whomever you chose) will be when he shows them what he got for being good ! Remind him OFTEN through the store when you first begin this, so his excitement and willingness to cooperate stay fresh in his mind.
Start with very short practice trips to the store, so you can set him up for success early on, before you expect success in a more trying situation.
However, if he "blows it" and throws a tantrum, DO NOT under ANY circumstances give in and give him that reward later.
A reward does NOT have to be expensive, nor does it have to be a sugary treat. Things like a page of stickers, a small bottle of bubbles, etc. will work just as well.
When you get to where you are going, before you leave the car, remind him one more time of the behavior you expect AND the reward for it, but if he displays the behavior you don't want (kicking, screaming, etc .... be specific with him) he will NOT get his reward, but will get time out instead.
IF this is a place he wants to go, like the toy store, ice cream place, play date, etc, it is okay to use leaving as a punishment, otherwise, leaving is not an option because that is very likely what he is wanting to do and you are unknowingly reinforcing his behavior when he gets what he wants, which is to leave.
He WILL test you a few times on this. The key is to let punishment or reward be swift and appropriate, and be consistant EVERY time. The key to success in any form of teaching is to be consistant.
Also, I personally, do not like to use "bed" as a punishment. Going to bed should be a pleasant experience. If it is sometimes used as a punishment, then when he occasionally doesn't feel like going to bed, he will feel as though he is being punished when you put him there, and you may begin to have problems getting him to bed at nap time or at night.
Time out in a specific corner or chair in your home that is reserved just for that purpose is a better option. When that space is used only for time out, he soon gets the idea that his behavior has been not so nice, and he is there because of it. Timing his time-out period begins when he has stopped throwing his fit, and is quiet. It's ok if he is crying in time out, as long as it is quietly and not an all out tantrum. Timing never starts before the tantrum has ended. Then match the number of minutes to his age. In his case, 2 minutes.
When his minutes are up. Talk to him and explain why he was in time out and help him to understand how he could have avoided time out.
"Time out" is just that. It is taking time out from a situation where the child has lost control of himself, and/or become completely frustrated to the point of acting out, and needs to regain his control of himself.