Google Maps API in Rails (YM4R-GM) – Part I: Installing the beast

June 27, 2009 at 9:42 am 5 comments

Environment: Rails 2.3.2, Windows Vista, SQLite3 development on a local box

So, you want to be able to use Google maps in your mashup project. In order to do that, there is a nice plug-in YM4R that supports Google Maps and Yahoo APIs and is quite easy to use once you get through the hurdle of installing (if you are on a Windows system). So I split this post into 2 parts – one is the installation, the other – usage of the plugin itself.

Installation

Installation in theory seems to be quite easy, you just need to install a gem and then install a plugin that uses this gem (update: looks like ym4r-gm doesn’t require the gem anymore, so try installing the Git plugin without the gem first – see below).

Here are the instructions:

gem install ym4r
ruby script/plugin install svn://rubyforge.org/var/svn/ym4r/Plugins/GM/trunk/ym4r_gm

SVN

However, if you are one of the unlucky ones with a Windows development environment, most probably you do not have an SVN client installed. A bad thing about this is that the plugin install command above does not show any error messages, so you can run the program with -x switch or just check the vendor/plugins subdirectory of your project – it should have the directory ym4r_gm in it. If it doesn’t, you need to install an SVN client. Installing an SVN client is a minor pain (I chose a command-line version that is 3mb, but you can’t just download, you need to register to get the file), and after installing it actually gave me an error that looked like this: “svn: error resolving case of” and the local path to the plugin. Googling this error leads to a lot of posts from other clueless newbies, and as I really had no experience with SVN, it looked like in order to solve this problem I needed to read a book on SVN first. One option that I used was to download the GUI client TortoiseSVN and copy the repository to a local disk.

Github

Thankfully, there is an easier way. The YM4R-GM is actually copied to Github, which allows you to download the package without the client. And it’s actually a newer version of the plugin. So, here is the Github page for YM4R-GM.

A Windows client for Git can be downloaded here.

After you download a client (I’ve installed this one, but check for the latest version), you can run Git installations, and actually it does so without problems. If you get a path not found problem, you will need to close and reopen your cmd window, because new Windows PATH setting is not visible to an “old” window.

Here is the line:

ruby script/plugin install git://github.com/ewildgoose/ym4r_gm.git

Manual install

Ok, you can stop right here ;). But just in case you will come into any problems or will find a project which is on SVN only, you can download the files manually and put them in vendor/plugins/[name-of-plugin] directory. For most of the plugins that’s enough, but YM4R-GM also installs files into other directories, so you should (1) copy its javascript files into public/javascripts and (2) file in the root of the plugin called gmaps_api_key.yml.sample needs to be copied to config directory with the name gmaps_api_key.yml.

However, you can also just as easily go into the plugin directory and run ruby install.rb

Google MAP API key

Final thing you need to do is to get an API key from Google. Here is the link. You need to get a link for each url that you use. If you only use the development environment now, put the URL of the site as http://127.0.0.1. Copy the API key that you receive and put it in the development section of the gmaps_api_key.yml you created earlier.

Well, that’s it. It took longer than usual, but it was worth it 😉

Advertisements

Entry filed under: Uncategorized. Tags: , .

Michael Jackson RIP Google Maps API in Rails (YM4R-GM) – Part II: Usage

5 Comments Add your own

  • 1. vladimir  |  October 13, 2009 at 3:10 am

    Hi,

    Thanks a lot for your post. I have spent quite some time trying to figure out why plugin install wasn’t producing any results and no other posters mentined the “silent” error of not having svn client installed.

    Reply
  • 2. Christian  |  November 2, 2009 at 3:33 am

    Thanks for this. To copy the javascripts to /public/javascripts was my missisng.

    rock on!

    Reply
    • 3. allaboutruby  |  November 2, 2009 at 9:29 pm

      yeah, it’s a tricky one. still, there are no problems with github install.

      Reply
  • 4. Eddy Josafat  |  November 10, 2009 at 9:08 pm

    Nice tutorial!

    The latest versions of the plugin doesn’t require installation of the gem unlsess you want to use special features.

    quoting the plugin’s author:

    “With the plugin, you don’t need the YM4R gem anymore, unless you want to use the tilers or the Ruby helpers for the Yahoo! Maps Building Block API’s and the Google Maps geocoding API. Please refer to the documentation of the YM4R gem to know more about the functionalities in it.”

    Reply
  • 5. klaas debeuf  |  February 8, 2010 at 7:17 pm

    thanks , nice tutorial

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent posts

Starting to learn Rails?

Kindle

Get Kindle - the best e-book reader, that I personally use, and the only one that you can read on the beach - very useful: Kindle Wireless Reading Device (6" Display, Global Wireless, Latest Generation)

%d bloggers like this: