You need to put the behaviour on cue.
- What you do is reward him whenever/wherever he does it at first, but super jackpot reward if he does it while out on a walk.
- When you have done quite a few rewards after he's 'gone' you start to say a word which you can pair with the action. (It is important to say the word actually as he is 'performing the action' so to speak.) Then reward immediately.
- Next step would be to take him to the place you would like him to go (probably near to a dog waste bin on your walk) say the word and reward him big time if he does it. If he doesn't just ignore, carry on your walk as usual and make sure he has had a few more rewards under his belt before trying again.
Its like any other dog behaviour, they just need to understand what you are asking of them and to do that you have to pair the action with the command and reward them for carrying it out.
Popular words to use include 'busy' or 'business', but the word is not important, just choose something you won't be embarrassed saying in a public place.
(One important thing, never scold him for going in the wrong place, especially once you have starting the process of getting the action on cue.)
The length of time it will take to train will depend on the dog, some pick it up straight away others may take a couple of weeks.
If you have any experience of clicker training, this would really speed up the process.
Its a great thing to teach your dog and so useful if you are travelling as you can stop and get him to 'go' without having to go for a long walk.
If he is still just a pup, it is quite normal for pups to refuse to go anywhere but on their own territory (all those other big dog smells in the park can be a bit overwhelming) - my old boxer x gsd went 4 days refusing to go when we were on holiday when he was a pup! There's no reason not to get started with the training though.