Server script: Geocode address with Google API?

I’d like to use the Google Geocode API to get an address’ latitude and longitude, when the doctype is saved (if there isn’t already a latitude/longitude there).

I’m assuming the best way to do this would be to use a server-side script.

Has anybody implemented this before?