“A common operation in Maps API applications is to search a spatial database for locations within a certain distance of a point,” says Thor Mitchell, Maps API Product Manager. “It can also be useful to offer search along a route, for example to find hotels, restaurants, or service stations on a long journey.”
“However if your spatial database does not support corridor queries this can be difficult to implement efficiently,” adds Thor. “For example searching around every vertex of a route will generate a large number of queries which overlap, while also leaving gaps in coverage between widely spaced vertices.”
Documentation for implementation can be found here. There are essentially ten steps, which are illustrated neatly on that page.