for me (and me only I guess being an experiment of one) I've had to deal with this in two ways
1) the almost immediate, about 2 miles in (so also two miles from home) urge - this one seems to be related to the previous evenings food/drink intake and can be influenced by an organised evening event. If I'm getting up at 5:30, throwing on my kit and running out the door, another half hour before for a cup of coffee is not an option.
2) the about an hour or so into a long run urge - havent worked this one out yet as I try predominantly to run aerobically. Doesn't seem to make any difference if I go pre-run
One thing I have noticed though, is hyper hydration can be your pre-race friend. Back when i was a rugby referee, I'd effectively hydrate all morning and generally ended up expelling the excess thourgh both pee and poop, which meant I ended up going about three times in the morning before the match, but never during.
My solution? Always carry paper, and look out for off road hidey places on regular routes.