<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Perspectives : Writings from The Killswitch Collective</title>
    <link>http://www.killswitchcollective.com/blog/index.xml</link>
    <description>Perspectives is the blog of The Killswitch Collective, a Chicago-based web development, design and communication firm.</description>
    <language>en-us</language>
    <item>
      <title>Google Maps on Rails</title>
      <category>Development</category>
      <description>The Google Maps API is without a doubt one of the most popular APIs available on the web today. It offers webmasters the ability to add mapping functionality, similar to maps.google.com, to their websites. All of Google Maps functionalities, including markers, directions, zoom options and satellite view are only a few lines of code away. But before we get started with the code portion, you will need a Google Maps API key.

Getting a Google Maps API key takes a minute and costs nothing. Just sign in to your Google Account (I am sure you have one) and head to http://code.google.com/apis/maps. On the right hand side you will see &#8218;How Do I Start, where you will just simply click on Step 1 "Sign up for a Google Maps API key". Then enter your site's live domain, accept the terms and click the "Generate API Key" button.

On the next page your unique API key will appear. Make sure that you copy and paste it to a safe location. Below the API key will be JavaScript examples to quickly get you started. In this tutorial, we will generate similar code with the use of some rails plug-ins. The most popular plug-in is the Yellow Maps for Ruby, also known as YM4R. Since there are other mapping APIs, this plug-in comes in a few flavors. Since we're doing Google Maps, we will use YM4R/GM.
&lt;br /&gt;
&lt;br /&gt;
1. Lets start by generating a new Rails application:

&lt;pre&gt;rails map_example -d mysql&lt;/pre&gt;


2. Create a 'map_example_development' database and remove index.html from the public folder
&lt;br /&gt;&lt;br /&gt;

3. The lets add a controller and the index action

&lt;pre&gt;ruby script/generate controller location index&lt;/pre&gt;


4. Lets install the YM4R/GM plugin

&lt;pre&gt;ruby script/plugin install git://github.com/queso/ym4r-gm.git&lt;/pre&gt;


5. Add frontend.html.erb in app/views/layouts with the following code:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="punct"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color:#DA4939"&gt;DOCTYPE&lt;/span&gt; &lt;span class="ident"&gt;html&lt;/span&gt; &lt;span style="color:#DA4939"&gt;PUBLIC&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;-//W3C//DTD XHTML 1.0 Strict//EN&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;

&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;html&lt;/span&gt; &lt;span class="ident"&gt;xmlns&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="ident"&gt;xml&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:lang=&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;en&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="ident"&gt;lang&lt;/span&gt;&lt;span class="punct"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;en&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;head&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
	&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;title&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#DA4939"&gt;Google&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Maps&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Rails&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Example&lt;/span&gt;&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="regex"&gt;title&amp;gt;
	
	&amp;lt;%= GMap.header %&amp;gt;
	&amp;lt;%= @map.to_html unless @map.blank? %&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span class="punct"&gt;/&lt;/span&gt;&lt;span class="ident"&gt;head&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;body&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
	
&lt;span class="punct"&gt;&amp;lt;%=&lt;/span&gt;&lt;span style="color:#A5C261"&gt; yield %&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;span class="normal"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;

Note that we have included two YM4R/GM lines in the head section. The GMap.header will include needed JavaScript files while the @map.to_html line generates JavaScript based on the parameters passed into the map object. We will be creating the @map object in our location controller.
&lt;br /&gt;
&lt;br /&gt;
6. Don't forget to specify the layout in app/views/location_controller:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="ident"&gt;layout&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;frontend&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;


7. Inside of the index action, add the following code:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="ident"&gt;coordinates&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="number"&gt;41.8921254&lt;/span&gt;&lt;span class="punct"&gt;,-&lt;/span&gt;&lt;span class="number"&gt;87.6096669&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;

&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span style="color:#DA4939"&gt;GMap&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;control_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:large_map&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#DA4939"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:map_type&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#DA4939"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;center_zoom_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;coordinates&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt;&lt;span class="number"&gt;14&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;overlay_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span style="color:#DA4939"&gt;GMarker&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;coordinates&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:title&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;Navy Pier&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:info_window&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;Navy Pier&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;))&lt;/span&gt;
&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;

First we set our map coordinates into an array. The first number is the latitude and second is the longitude. These coordinates point to Navy Pier in Chicago, Illinois. If you would like to try a different area for this example, this easy tool (http://stevemorse.org/jcal/latlon.php) provides you the latitude and longitude for any address you want to use..

Next, we set the @map object to pass into our view. The @map object contains a new instance of the GMap class; the "map" string is the id of the div that will contain the map. The next line activates controls for our map. The large map activates the zoom option while the map type activates various views such as a regular map, satellite or terrain. Then we set the default map center and zoom. We first pass in the coordinates array so our location will be centered, then we pass in a integer to determine zoom level. This integer can be between 0 and 22, the higher the number the more the zoomed in the map will be. Finally, we add a marker overlay. The first argument is the coordinates and it is the only required argument need to add a marker. The title and info_window are both optional, title is the text that will display when your mouse is idle over the marker, while info_window is the text that will appear in the pop up box that appears after clicking the marker.
&lt;br /&gt;
&lt;br /&gt;
8. Next open our view file located at app/views/location/index.html.erb and add the following:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;h1&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#DA4939"&gt;Google&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Maps&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Rails&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Example&lt;/span&gt;&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="regex"&gt;h1&amp;gt;

&amp;lt;%= @map.div(:width =&amp;gt; 800, :height =&amp;gt; 500) %&amp;gt;&lt;span class="normal"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;br /&gt;
9. Map the homepage to the index action of location by adding the following to config/routes.rb.

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;root&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:controller&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;location&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:action&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;index&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;


10. Fire up your rails application and a map should appear.


Currently our map is static and the location can't change. It would be nice to have a option to change the location through a text field. Since it is a text field, the user will be able to type in any possible location and expect our application to map it. We're going to have to convert user-inputted text into map coordinates. Sounds complicated, luckily there is another rails plug-in that can be of help here and that plug-in is Google-Geocoder. Google Geocoder will find 

11. Install the Google-Geocoder plugin:

&lt;pre&gt;
ruby script/plugin install git://github.com/tobstarr/google-geocoder.git
&lt;/pre&gt;


12. Next add the form to the bottom of the view:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="ident"&gt;br&lt;/span&gt; &lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="punct"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="ident"&gt;form_for&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;new_location&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:url&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;location_index_path&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:html&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:method&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:post&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt; &lt;span style="color:#CC7833"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;
	&amp;lt;label&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#DA4939"&gt;Enter&lt;/span&gt; &lt;span class="ident"&gt;a&lt;/span&gt; &lt;span class="ident"&gt;new&lt;/span&gt; &lt;span style="color:#DA4939"&gt;Location&lt;/span&gt; &lt;span class="ident"&gt;to&lt;/span&gt; &lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;:&amp;lt;/&lt;/span&gt;&lt;span class="regex"&gt;label&amp;gt;&amp;lt;br &lt;/span&gt;&lt;span class="punct"&gt;/&amp;gt;&lt;/span&gt;
	&lt;span class="punct"&gt;&amp;lt;%=&lt;/span&gt;&lt;span style="color:#A5C261"&gt; text_field_tag :new_location %&amp;gt;
	
	&amp;lt;%&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;submit_tag&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;Map It&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;
&amp;lt;% end %&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;


13. We will then add the create action to the location controller:

&lt;pre style="background-color:#2B2B2B;color:#E6E1DC;padding:6px;overflow:auto;line-height:12px;font-size:12px;padding:6px;"&gt;&lt;code&gt;&lt;pre&gt;&lt;span style="color:#CC7833"&gt;def &lt;/span&gt;&lt;span class="method"&gt;create&lt;/span&gt;
	&lt;span class="ident"&gt;new_location&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:new_location&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
	
	&lt;span class="ident"&gt;gg&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span style="color:#DA4939"&gt;GoogleGeocode&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;Your API Key Here&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
	&lt;span class="ident"&gt;gg_locate&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;gg&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;locate&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;new_location&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;

	&lt;span class="ident"&gt;coordinates&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="ident"&gt;gg_locate&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;latitude&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;gg_locate&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;longitude&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;

	&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span style="color:#DA4939"&gt;GMap&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
	&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;control_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span style="color:#6E9CBE"&gt;:large_map&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#DA4939"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:map_type&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span style="color:#DA4939"&gt;true&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
	&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;center_zoom_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;coordinates&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt;&lt;span class="number"&gt;14&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
	&lt;span style="color:#D0D0FF"&gt;@map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;overlay_init&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span style="color:#DA4939"&gt;GMarker&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;coordinates&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:title&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;new_location&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:info_window&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;new_location&lt;/span&gt;&lt;span class="punct"&gt;))&lt;/span&gt;

	&lt;span class="ident"&gt;render&lt;/span&gt; &lt;span style="color:#6E9CBE"&gt;:action&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#A5C261"&gt;index&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
&lt;span style="color:#CC7833"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/code&gt;&lt;/pre&gt;


A few lines of the create action is similar to the index action. First we set the new_location variable to the value of the new location parameter. Next we pass in the Google Maps API key to a new instance of the GoogleGeocode class, this will allow us to run methods such as "locate" which will return coordinate information. Then we set the coordinate array and the rest is familiar territory. The only difference is we are setting the title and info window text to the user input and finally we reuse the index template.

That's it for my Google Maps on rails tutorial, we were able to get a functioning map by using the YM4R plug-in. Then we were able to map user-inputted locations by using the Google Geocoder plug-in. You could easily expand this example by giving the users the ability to map multiple locations at once or dry up similar code used in our index and create methods.</description>
      <pubDate>Fri, 24 Jul 2009 12:17:29 -0700</pubDate>
      <link>http://www.killswitchcollective.com/articles/65</link>
      <guid>http://www.killswitchcollective.com/articles/65</guid>
    </item>
  </channel>
</rss>
