If you are stopped or detained for taking photographs, the first thing you should do is ask the police officer for their reason for stopping or detaining you. If there is no valid reason, then you are within your right and should not be detained or arrested.
If you're stopped on the street: stay calm, be reasonable, and be cooperative—by cooperative, that doesn't mean you have to show them your pictures when they ask. If you're not getting anywhere, ask to speak to a supervisor. Lastly, please be respectful, be polite, and act professionally.
If stopped for photography, the right question to ask is, "am I free to go?" If the officer says no, then you are being detained, something that under the law an officer cannot do without reasonable suspicion that you have or are about to commit a crime or are in the process of doing so. Until you ask to leave, you being stopped is considered voluntary under the law and is legal. If you are detained, politely ask what crime you are suspected of committing, and remind the officer that taking photographs is your right under the First Amendment and does not constitute reasonable suspicion of criminal activity.