static-gmaps: Google Static Maps API Interface 5

Posted by John Wulff Mon, 25 Feb 2008 21:32:00 GMT

I’ve written my first gem: static-gmaps. It provides a simple interface to the Google Static Maps API.

Usage

map = StaticGmaps::Map.new :center   => [ 40.714728, -73.998672 ],
                           :zoom     => 5,
                           :size     => [ 500, 100 ],
                           :map_type => :roadmap,
                           :key      => 'ABQIAAAA3HdfrnxFAPWyY-aiJUxmqRROGu07ZpoXmWqnENIWDDAF-b-TwhQ4JdQya7b6I5CihUtHtwmmBzWc0Q'
map.markers << StaticGmaps::Marker.new(:latitude => 40,
                                       :longitude => -73,
                                       :color => :blue,
                                       :alpha_character => :b)
map.url => 'http://maps.google.com/staticmap?center=40.714728,-73.998672&key=ABQIAAAA3HdfrnxFAPWyY-aiJUxmqRROGu07ZpoXmWqnENIWDDAF-b-TwhQ4JdQya7b6I5CihUtHtwmmBzWc0Q&map_type=roadmap&markers=40,-73,blueb&size=500x100&zoom=5'

Installation

sudo gem install static-gmaps

Documentation

http://static-gmaps.rubyforge.org

Update February 27, 2007: Added markers.

Comments

Leave a comment

  1. Avatar
    Galen about 21 hours later:
    Hot! What is that, like 48 hours after it was released?
  2. Avatar
    Tobi 13 days later:
    Hi! Just a little hint: I don't think it is good to provide a default zoom level and center (especially when that is in the middle of africa) to the links. The good thing when you use markers is that you add a couple of them to your map and without providing a center and/or zoom level and google picks the right parameters so that you get the best result. This does not work with your gem. Cheers, Tobi
  3. Avatar
    John Wulff 13 days later:
    Good idea Tobi. I'll do that for the next release.
  4. Avatar
    ben 7 months later:
    Hi, sorry to bother for this; i don't really get why a gem is needed if with a parametered url you get the image back, and that all the parameters are written in it again as they are above. I get this : map.url => 'bla... parameters... bla' but what is the above for ? I can't find clues neither in the doc; I might miss something in here; thanks for the further infos.
  5. Avatar
    hank 8 months later:
    I just found this plugin yesterday. I tripped up on this, so I figured that I'd mention it. You should update your RDOC readme so that people know how to include it in their ruby scripts or rails projects. The reason is that the require statement doesn't use the same name as your gem. So I had to dig in my lib/ruby/gems folder to figure it out.

    You need to type:
    require 'static_gmaps'

    In Rails 2.1 (should work for Rails 2.0.2 or greater) inside Rails::Initializer.run do |config|


    config.gem 'static-gmaps', :lib => 'static-gmaps'

Comments