Many fans of Trainspotting wonder where the name came from. Trains play no part in the movie's plot at all — they aren't mentioned by anyone, or ever alluded to, or even made to seem remotely significant in any way. There are only two real trains in the American release of the movie — a bird's-eye view of one roaring by between scenes, and the one the boys ride when Tommy drags them into the country for a walk. The beginning of the movie introduces the title while the squealing of trains plays in the background, and the wallpaper of Rents' room is lined with trains. But these minor appearences of trains play no important roles, so why the name?

In England in the 1980s, the term "trainspotter" started being used to describe those who track the schedules and car numbers of passing trains. This practice wasn't very widespread, so as time passed and the public became aware of the practice, the term became used as a mildly derogative term for anyone obsessed over minute details, to the point of obsessive-compulsion, of anything; once in Q magazine, it was used to describe Beatles fans (June 1995, p. 16).

[...] through the late '80s in Britain, it ["trainspotting"] began to mean anybody who was obsessive about something trivial, and part of that is drugs. It's a very male thing. Women, they know better. It was a way in which men would conquer an area of life by just knowing everything about all the Sean Connery films.
Danny Boyle, director of the 1994 movie Trainspotting

The first thing is that heroin users mainline along their arms and inject up and down on the main vein. 'Station to station,' they call it. And for addicts, everything narrows down to that one goal of getting drugs. Maybe 'trainspotters' are like that, obsessively taking down the numbers of trains.
Ewan McGregor, actor, "Mark Renton"

ZamZ points out a connection with the train station in Leith, and is quite right. "[...] the origin of the connection seems to be that the characters spend much of their time hanging out in the abandonded Leith Central Station [in the book]. Leith is now merely that part of the City of Edinburgh around the docks, but was once a seperate city. The closure of its railway station, the loss of civic identity and vigour that that represents, reflects the anonymous social vacuum in which the characters live."1

Furthermore, after enough intravenous injections of anything, the vein that's getting the injections begins to collapse and turn a dark purple color. Heavy heroin users experience this even if they rotate injection spots; eventually the veins begin to darken and become quite noticable. British and American slang both call these darkened veins "train tracks." Given the "trainspotting" definition of watching and tracking trains, if the two ideas are combined, a "trainspotter" may mean someone whose hobby is keeping track of train tracks from heroin use.

Even with this definition of the title, there isn't a very strong connection to a part of the story. Of course, the ideal person to ask would be Irvine Welsh, who wrote the book, but he has not commented on the title.

Finally, the WordTips email newsletter answered the question "What does 'trainspotting' mean?" on October 26, 1998. Their interpretation of the connection between the hobby and heroin use? "The movie was comparing the meaninglessness of heroin addiction with the pointlessness of trainspotting."2


References:
1: Bookshelved Wiki: http://bookshelved.org/cgi-bin/wiki.pl?Trainspotting
2: Cool List Digest Tue Oct 27 03:00:12 EST 1998: http://www.scumpa.com/pipermail/cool/1998-October/001074.html