A 37-year-old man who allegedly drove the getaway car that fled the scene of the fatal shooting of Cook County Associate Judge Raymond Myles has been charged with murder, police said Wednesday.

Joshua Smith is charged with first-degree murder, second-degree murder and obstruction, police said. The motive for the shootings was robbery and Myles was targeted — but the incident had nothing to do with his position as a judge, police said.

Myles was fatally shot about 4:50 a.m. Monday in the 9400 block of South Forest. His girlfriend, who was shot in a leg, is recovering.

Smith drove himself to the Area South Detectives division later that day “to speak with detectives” and has been in custody ever since, Chief of Detectives Melissa Staples said at a news conference Wednesday evening.

On Tuesday night, a car that left the murder scene was identified on video and recovered, police said. Tactical officers found it at about 11 p.m. Tuesday in the Calumet District on the Far South Side.

Cook County Associate Judge Raymond Myles | Cook County Circuit Court photo

Other people connected to the red 2005 Pontiac also were being questioned.

Staples said that the owner of the car isn’t suspected of being involved in the shootings.

When police found the car, officers noticed different license plates on the front and rear, Staples said. The plate that police saw in the security videos had been switched, she said.

Tests on shell casings found at the scene of the shootings showed the murder weapon was previously used in an armed robbery in January in which the victim was shot and wounded, Staples said. It underscores the problem of illegal guns being used over and over in Chicago, she said.

It appears Smith had fleeting contact with the judge about 16 years ago.

In 2001, he appeared before Myles on a charge of failing to have a title for a vehicle, but the case was dismissed, court records show.

The next year, Smith was charged with armed robbery with a firearm. He was convicted in 2003 and sentenced to six years in prison, records show.

Detectives said Myles walked out of his house after his girlfriend was shot and exchanged words with the assailant before he was gunned down on a back porch.

A Chicago Police car in front of the home of Cook County Associate Judge Raymond Myles, 66, in the 9400 block of South Forest. Myles was fatally wounded Monday morning. | Leslie Adkins/For the Sun-Times

A neighbor told the Sun-Times he heard a woman scream, “Don’t kill him! Don’t kill him!” and then heard about five shots.

Neighbors said the 66-year-old judge, whose career spanned nearly two decades, often left the house early in the morning with his 52-year-old girlfriend to work out.

The FBI offered a $25,000 reward for tips leading to an arrest.