Phone records showed a call was placed from the home of Roof's mother, where he lived, in February 2015 to the church.
Joseph Hamski told jurors that the self-described white supremacist began making the two-hour trips from his home in Columbia, South Carolina, after downloading a book about the Ku Klux Klan with photographs of a cross-lighting ceremony.
Roof would linger in the area, local media quoted Hamski as saying, staying for up to five hours at a time during which he also visited former plantations and other historic sites linked to the US South during times of slavery.
Phone records showed a call was placed from the home of Roof's mother, where he lived, in February 2015 to the church. A day later, Roof drove past Mother Emanuel, GPS data showed.
Roof documented the trips with photographs in which he struck various poses in front of the spots, sometimes wearing a jacket with the flags of apartheid South Africa and Rhodesia.
In one photograph, he stepped on the American flag.
Many of the images were posted in a hate-filled online manifesto that included racist language directed at African Americans and other minorities.
The now-defunct website, lastrhodesian.com, mirrored diatribes that filled Roof's leather-bound journal uncovered by the authorities.
In it, he directed some of his anger at gays and Jews, and penned a logo featuring several white supremacist symbols, including the numbers 14 and 88, the Celtic cross and a rune used by Nazis to represent Aryan heritage.
Roof, who has been described as a loner, also expressed regrets about having never fallen in love.
At least 50 FBI agents collected more than 500 pieces of evidence and conducted more than 200 interviews about the massacre at "Mother Emanuel," the oldest African Methodist Episcopal church in the US South.
In Roof's room, investigators found a pillowcase that he had shaped into a KKK hood, along with various drawings of KKK and Nazi symbols, and his camera containing thousands of photographs such as those with racist references.
A Walmart official said Roof had purchased ammunition on four separate occasions in the weeks leading up to the June 17, 2015 attack.
In a videotaped confession shown in court last week, Roof calmly told FBI agents interrogating him that he carried out the massacre in retaliation for alleged crimes committed by black people against white victims.
The prosecution plans to rest its case Thursday, and US District Judge Richard Gergel said he may also give his instructions to the jury that day.
Jurors are bracing for gripping testimony expected Wednesday from Polly Sheppard, one of the three survivors of the attack, and from the medical examiner, who collected 54 bullets or fragments from the bodies.
The first person to testify in the trial was another survivor, Felicia Sanders, who gave a heartrending account last week of how she lay in a pool of her son and her aunt's blood while cradling her granddaughter as the massacre unfolded.
She called Roof "evil" and said "there's no place on Earth for him except the pit of hell."
The defense team suffered another setback at the start of Tuesday's hearing when Gergel denied a motion to present evidence about Roof's mental state during the current phase of trial where jurors are weighing his guilt, not his sentence.
Assistant US Attorney Jay Richardson objected to what he called "self-serving hearsay" that would be used to justify Roof's crime.
Roof, 22, plans to represent himself during the sentencing phase, and his lawyers are seeking to spare him the death penalty.
Prosecutors refused to accept his offer to plead guilty to the 33 federal charges against him, including hate crimes and religious obstruction, in exchange for a life sentence. So Roof then entered a not guilty plea.
The accused gunman is also facing state murder charges in South Carolina that could see him sentenced to death. That trial is not due to begin until January 17.