Rails apps that overlay routes on Google Maps?

87 views
Skip to first unread message

Scott Garman

unread,
Nov 9, 2009, 1:26:24 PM11/9/09
to pdx...@googlegroups.com
Hello,

I was wondering if anyone could point me to one or more open source
Rails applications that use Google Maps to display routes, preferably
based on one of the XML GPS file formats.

Most of the time the Google Maps api is used to simply mark a single
point on a map, and I'm having trouble finding examples where full
routes are displayed.

Thanks,

Scott

--
Scott Garman
sgarman at zenlinux dot com

Leif

unread,
Nov 16, 2009, 6:32:01 AM11/16/09
to pdxruby
Do you want to turn the GPS XML into Google Maps KML to display?

The Google Maps API (for JavaScript) has a GPolyline which is probably
what you'd use to draw a route, just pass in a list of coordinates.

There's a couple adapters for Rails that wrap this JavaScript for
you. One of which (YM4R) has a simple tutorial on displaying a
shapefile describing a polygonal area on Google Maps:
http://ym4r.rubyforge.org/tutorial_ym4r_georuby.html
The other I can't recall the name of at the moment, but I believe it's
used in Calagator to display the venue location on the map.
Hope this helps,
-Leif

Bryan

unread,
Nov 16, 2009, 10:38:22 AM11/16/09
to pdx...@googlegroups.com
I haven't tested it out yet, but someone has forked the YM4R/GM plugin to include Google Directions:
http://github.com/queso/ym4r-gm/commit/77821351d5f5b0c536e5fbdf89a4c853162ffa96

I'll try this out, hopefully today, and let you know how it works.

Bryan

Bryan

unread,
Nov 16, 2009, 4:46:52 PM11/16/09
to pdx...@googlegroups.com
Scott, I got this working over lunch.. I can send a demo app if you want. Here's the basics using the YM4R/GM plugin:

The plugin from fork listed below assumes you have a javascript function named handleErrors().  You can just put a dummy function in your application.js file or use the javascript from here (view the source): http://code.google.com/apis/maps/documentation/examples/directions-advanced.html

You have to add some things to your layout file....
The html tag needs some google stuff:
<html xmlns="http://www.w3.org/1999/xhtml" <%= GMap::VML_NAMESPACE %> >
In your head section add:
 <%= GMap.header %>
 <%= @map.to_html %>

Example controller action:
class MapsController < ApplicationController
  def index
    points = [[45.554067,-122.675829],
    [45.5517378,-122.6755129],
    [45.549588,-122.67511],
    [45.548305,-122.675558],
    [45.540794,-122.675448]]
    @map = GMap.new("map_div")
    @map.center_zoom_init([45.549588,-122.67511], 13)
    @map.directions('map_directions',points)
  end
end

Example view:
<h2>GMap with Directions</h2>
<%= @map.div(:width => 400, :height => 400) %>
<div id='map_directions'>
</div>

.. and you need a gmaps config YAML file (the below works for localhost):
development:    ABQIAAAAzMUFFnT9uH0xq39J0Y4kbhTJQa0g3IQ9GZqIMmInSLzwtGDKaBR6j135zrztfTGVOm2QlWnkaidDIQ

Scott Garman

unread,
Nov 16, 2009, 5:13:15 PM11/16/09
to pdx...@googlegroups.com
Leif and Bryan: thanks so much for your responses/examples. I'm going to
dig more into this tonight and do some exploration.

Thanks!

Reply all
Reply to author
Forward
0 new messages