Class: Route

Inherits:
Object
  • Object
show all
Defined in:
lib/route.rb

Instance Method Summary collapse

Constructor Details

#initialize(id, code) ⇒ Route

Returns a new instance of Route.



5
6
7
8
# File 'lib/route.rb', line 5

def initialize(id , code)
    @id = id
    @code = code
end

Instance Method Details

#route(start, destination) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/route.rb', line 9

def route( start, destination)
    s = loc(start)
    d = loc(destination)
    url = "https://route.api.here.com/routing/7.2/calculateroute.json" + "?app_id=" + @id + "&app_code=" + @code + "&waypoint0=geo!" + s  + "&waypoint1=geo!"  + d + "&mode=fastest;car;traffic:disabled&metricSystem=metric"
    request = Net::HTTP::get(URI(url))
     res = JSON.parse(request)
     dis = res["response"]["route"][0]["summary"]["distance"]
     tie = res["response"]["route"][0]["summary"]["baseTime"]
     km = dis/1000.0
     t = ""
     if tie > 3600
         h = tie/3600
         tie = tie%3600
         t = h.to_s + ' hours :'
     end
     t = t + (tie/60).to_s + ' minutes :' + (tie%60).to_s + " seconds" 
     return km.to_s, t
end