aku-aku: v.. To move a tall, flat bottomed object (such as a bookshelf) by swiveling it alternatively on its corners in a "walking" fashion. [After the book by Thor Heyerdahl theorising the statues of Easter Island were moved in this fashion.] source: LangMaker.com. Aku Aku also has another meaning to the islanders: a spiritual guide.
« lost beatles track found! | Main Page | prediction: agents make a comeback »
Google Maps on Rails
Posted by dav at 2005 April 24 06:23 PM
File under: Geek

Quick summary: I've got some code here that should let you pretty easily add custom google maps to your rails app. It's far from complete but it's enough to get you going.

It's based on work from Anselm Hook (who looks like this), which was based on work from Phil at mygmaps.com, which of course is based on Google Maps which has a copyright notice like every two lines in their obfuscated javascript code. Phil, Anselm and I are all open source for the community types but don't even try asking me about licensing, we're probably all going to hell. Come on in, the water's warm.

I started with Anselm who had taken cues from Phils work to get a Drupal-ized version working for CivicMaps.org. He had posted some samples, which were a bit screwy at first but he worked with me to get a cleaned up version that comes down to three files: inner.html, data.xml and xform.xsl. The idea is that inner.html would be included in another html file like this:

<iframe src="http://myhost.com/inner.html" width="600" height="400" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" ></iframe>

but for testing you can just load inner.html directly.

You should be able to drop all three files into a directory on your web server, edit the xml to make sure it's pointing to the right place for the xsl and the icon pngs, edit the html to make sure it's pointed in the right place for the xml, and then load inner.html in your browser. You can figure it out from there.

So what I did was take this and replace the need for a data.xml file with the ability to create the pinpoint xml dynamically in a Ruby on Rails application. You can try it out by downloading this GMoR.zip file and unzipping it in your rails application directory. It should create the following files (you should make sure you didn't happen to have anything of the same name that would get overwritten):

app/views/gmap/gmap.rhtml
app/views/gmap/inner.rhtml
app/controllers/gmap_controller.rb
app/helpers/gmap_helper.rb
lib/GmapLocation.rb
lib/GmapMap.rb
public/man.png
public/xform.xsl

To see the default map, just load http://yourrailsbox.com:3000/gmap/gmap (if you're using WebBrick anyhow).

To make your own map, edit gmap.rhtml to change the properties of the GmapMap and GmalLocation objects created there.

I just got all this working, so I'm sure there's bugs. I wanted to post it anyhow though, since I'm not sure when I'll have time to play with it more. I suppose if it were cleaned up it would be good to make it a gem-installed generator. Maybe some day.

Comments:

This tip looks worthwhile. I'm trying to play around with this stuff to get me going. However with the code supplied, at least on the latest rails updates, I can't seem to get the map to appear. Is it just because this is a little out of date? Or am I missing the obvious?

Thanks for any help clearing this up.

Posted by: JasonBelec on January 18, 2007 06:17 PM

Oh yeah, this is waaaaaay out of date. Check out O'Reilly's Google Map Hacks book if you want something a bit more up to date. Or just go straight to the Google Map API.

Posted by: dav on January 18, 2007 09:44 PM

Instead of loading the API from http://maps.google.com/apis, you load the common loader from http://www.google.com/jsapi. You can pass your existing Google Maps API key to this URL:

Posted by: Ch.Srinivas Reddy on May 20, 2008 02:54 AM

Post a new comment:

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?