A common operation in Maps API applications is to search a spatial database for locations within a certain distance of a point. 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. 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.

RouteBoxer is a new addition to the Open Source Utility Libraries for the JavaScript Maps API v2 and v3 that can help. It enables search along a route to be quickly and easily implemented against any spatial database that supports bounding box queries, such as the Google Maps Data API. The RouteBoxer class takes a Polyline object or array of LatLng objects and returns a set of non-overlapping bounding boxes that are guaranteed to encompass every point within a specified distance of the line.

You can use the below demo to evaluate the boxes that are generated for a given route.

For information on how to use RouteBoxer in your applications, see the RouteBoxer documentation for Maps API v2, and Maps API v3.