Google Maps API in ajax-call

I'd like to use some functionality of the Google Map API in an ajax-
request, but i'm having some troubles inplementing that. What i want
to use is the possibility of calculating the distance of a route
between 2 cities.

In this example...

...are these the two lines that i need (slightly altered)

directions = new GDirections();
directions.load("500 Memorial Drive, Cambridge, MA to 4 Yawkey Way,
Boston, MA 02215 (Fenway Park)");

After this, the distance is in in directions-object. I'd like to be
able to put this in an rjs, but that doesnt work at the moment, since
there is some javascript from Google being run in the head of the
document and without it, GDirections is unknown.

How can i make sure this script is being loaded/run within my rjs-
file? I tried pasting the whole contents of that file into my rjs, but
it already gives me an error (dynamic constant assignment) on the
first line (var G_INCOMPAT = false;)

Any ideas on this?