Platinum Partner

Get Google Maps Informations (distance And Time, French Version)

Here a little script to get time and distance between two towns with google maps. You can change "voiture" by your langage word "car", or anything else.

this is a command line version : # ruby myscript.rb "Lyon" "Paris"
You can easily change it for a Ruby on Rails project :)
Maybie we can upgrade this script using regexp.


require "open-uri"
require "cgi"

# Command line arguments ... 
$*.each {|argu| argu.gsub!("\"","")}
# Defaults towns
src = "Lyon"
dest = "Paris"
# If we have fill two aguments ...
if $*.size == 2 then
        src = $*[0]
        dest = $*[1]
end

html = ""
url = "http://maps.google.com/maps?f=d&hl=fr&saddr=" + CGI.escape(src) + "&daddr="+ CGI.escape(dest)
# Read the html page
open(url) {|f|
        f.each_line {|line| html += line}
}
pos1 = html.index("voiture") # French version
pos2 = html.index("",pos1) unless pos1 == nil
pos1 = html.index(">",pos2+6)+1 unless pos2 == nil
pos2 = html.index("",pos2+1) -1 unless pos2 == nil
ret = ""
if pos1 != nil and pos2 != nil
        ret = html[pos1..pos2].gsub!(" ", " ")
else
        ret = "0"
end
html = nil
p ret
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}