title: Passing parameters to/from JavaScript & Rails
body: <p>In my Rails app I have a helper method <strong><code>location</code></strong> that gets the coordinates for a given IP address and makes them available across all controllers and views. For example <strong><code>location.latitude</code></strong> returns the latitude of the user. You get the idea.</p>
  
  <p>I also have some Javascript that draws a Map from the Google Maps API based upon a given lat/lon pair. The problem is that I have no idea how to pass the <strong><code>location</code></strong> params into the JavaScript!</p>
  
  <p>The JavaScript resides in 'application.js' and looks like this:</p>
  
  <pre><code>$(document).ready(function() 
    { 
  
      //Map options...I want the params to go into the var 'MapOptions' below
  
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(40.764698,-73.978972),
          zoom: 13,
          mapTypeId: google.maps.MapTypeId.ROADMAP
          };
  
      //Setup and Draw the Map...
      //....................................
    };
  </code></pre>
  
  <p>The map itself gets called in the HTML like so. There isn't an obvious way to pass params.</p>
  
  <pre><code>&lt;div id="map_canvas"&gt;
    &lt;!-- The Map gets drawn here! --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I know this is probably an obvious question, but I've never had to pass a parameter from my application to Javascript this way before.</p>