This remains a problem for me - my LE career was 100% plain clothes.
And it is a bigger problem than some think. Right now, in any city or town, you can have plain clothes local cops, sheriffs, Marshals/Constables, State Troopers, State Liquor, drug, vehicle, etc. etc. officers, and the entire alphabet soup of Feds: FBI, DEA, ATFE, ICE, IRS, and on and on, plus all their Inspector Generals, all armed.
As for badges, you can buy "Concealed Weapon Carrier" badges on the net, or at the flea market - a bad idea in my mind.
So, how do you sort them out? As already noted, put your gun down and play 'kiss the concrete' until things settle down.
NOTE: I do not use the phrase 'drop the gun' - dropped guns can go off, and if it is mine, I usually carry a custom made gun that I don't want damaged. I will put the gun down in a manner that makes it clear I am complying with orders.