9

google maps in two or more lines of code

 3 years ago
source link: https://technomancy.us/15
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I just commited a new version of the Cartographer library that lets you put nifty Google Maps into your Rails apps in a jiffy. It's available as a plugin, so if you are using Rails 0.14.3 or newer, a simple script/plugin install -x svn://dotsx.usc.edu/cartographer/branches/pnh/vendor/plugins/cartographer will get you started. You will also need to:

  • Get a Google Maps API key
  • Put your API key into the hash Cartographer uses (currently in lib/cartographer.rb)
  • Add the line <%= gmaps_header %> to the pertinent layout(s)
  • Create a map in your controller or model:
    @map = Map.new(: name => 'mymap', : width => 300, : center => [-110, 33])
  • Display the map in your view: <%= @map.to_html %>
  • You can add markers as well:
    @map.markers << Marker.new(: position => [lng, lat],
            : info_window => 'You <i>clicked</i> my marker')

Under older Rails versions you can just svn co svn://dotsx.usc.edu/cartographer/branches/pnh/vendor/plugins/cartographer to get it. I hope to have the RubyForge page updated soon.

Happy hacking!

Oh yeah, and my server is running Rails + Lighttpd + Postgres now instead of crappy homebrew Lisp HTTP server and Apache2. It's amazing: Typo doesn't crash any more—not even on live search! Though Lighttpd absolutely hates my Trac installation; I may have to move to Trac's HEAD so FastCGI works.

Also started reading Stephen Levy's Hackers. It seriously reads like L' Morte d' Arthur. Good stuff.

« older | 2005-11-08T14:50:22Z | newer »

All posts | Résumé | Projects | Talks | Colophon | Technomancy is © 2004 – 2020 Phil Hagelberg


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK