I do a lot of work with Google Maps. Many times when I geocode an address, I need the closest lat/lon of the nearest street, *not* the lat/lon of the address itself. Why do we need to do this? Well, consider the scenario where we need to compare the driven route of a person with the locations he is supposed to be visiting. With normal geocoding the lat/lon of the place will be in the center of the place’s boundary. While this is okay for a regular house, the center of a hospital or a farm is going to be too far from the street. So what we need is the closest street lat/lon for that place.

So how do we do it? There is nothing in Google Maps API that allows us to specify a “snap to street” attribute when requesting a geocode. But… there is a pretty handy Directions service. What you do is you geocode the place, take the lat/lon, make it the begin and end point and call the directions service. The first leg’s first lat/lon will be the one that we want.

To see it in action, go to http://dev.agilissystems.com/~nbari/snap.html

See the source to see how it’s done. Also, full disclosure, I am not the original author of this cool trick, this has been around the intarwebs for a while now.