The code above calls the service; then parses the resulting JSON to retrieve the distance and displays that distance in a DIV with the ID distantDiv. In this example, I hard-coded the 2 addresses, but you could use jQuery selectors to retrieve the address from elements on the page or user input.

Response

Below is part of the Json response to the service call

Limitations

There are some limitations you should be aware of. I am a cheapskate, so I’m using the free version of this API. With the free version, I can only send 2500 addresses per day. If I try to send more, the service will respond with a status of “REQUEST_DENIED” and no results will be returned.

Also, Google expects you to display the results on a Google Map. I’m not sure how they enforce this, but they don’t allow you to use the Geocoding API to display data on someone else’s map.