# Google Maps API in ajax-call

**URL:** <https://www.ruby-forum.com/t/google-maps-api-in-ajax-call/137234>\
**Category:** Rails\
**Created:** [May 10, 2008, 1:36pm UTC](https://www.ruby-forum.com/t/google-maps-api-in-ajax-call/137234 "2008-05-10T13:36:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [May 10, 2008, 1:36pm UTC](https://www.ruby-forum.com/t/google-maps-api-in-ajax-call/137234/1 "2008-05-10T13:36:44Z")

</div>

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…

[http://code.google.com/apis/maps/documentation/examples/directions-simple.html](http://code.google.com/apis/maps/documentation/examples/directions-simple.html)

…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?
