Pokemon battles can be triggered from any Pokemon gym on the map. Even if the gym is currently in control by the same faction as you, you will still be able to battle the other trainers. The game does very little to explain how the battles work, and the controls are not immediately obvious. This page will attempt to explain everything you need to know about Pokemon Battles in Pokemon Go.
The first thing that you need to know is the battles are NOT turn based. As soon as the battle begins you must start tapping your Pokemon on the screen for him to start attacking the other Pokemon that you are fighting against.
All Pokemon have 2 separate attacks. The primary attack, which is the weaker attack can be performed by tapping your Pokemon on screen. The faster you tap the faster the Pokemon will attack the opponent. There is a limit to how quickly you can attack and it all depends on the Pokemon you are using.
The secondary attack is triggered by holding down on your Pokemons back. The special attacks can only be performed if you have filled up one of the blue bars under your Pokemons name on the top left. Using the special attack will take away one full bar. You charge these bars up by unleashing attacks on the enemy Pokemon. These attacks are always way more powerful than the standard attacks, but also leave you open to attack from the enemy as you can not move while the move is being performed.
Once you have taken all of the opponents health the battle against that Pokemon will end. There is currently a known bug with the game that will prevent the opponent from being defeated.
There is a mechanic that allows you to dodge, but it currently does very little to help you against standard attacks. The dodge can be done by swiping left or right on the screen. When you do this you will see that the Pokemon hops in that direction. When the opponent is performing a special attack it can be a good opportunity to dodge it to save yourself taking some really big damage.
Healing can not be performed mid battle. Since the game is not turn based, you can only mash attacks and hope that you win the battle. Once the battle is over, you can go to the item menu and select potions or revives and apply them to the Pokemon that need them.
Every Pokemon has a weakness. Most are quite obvious and some make no sense at all. If you are about to battle against a water based Pokemon, it would be very unwise to use a fire based Pokemon for this fight as water beats fire. If you are unsure what to do in a battle, a good rule is to fight fire with fire. This can sometimes be very effective if you find that your pokemon has a higher CP and can easily beat that Pokemon. No pokemon will be weak to their own type.