Class: CloudMade::RoutingService

Inherits:
Service
  • Object
show all
Defined in:
lib/cloudmade/routing.rb

Overview

Class corresponding for CloudMade’s routing service

Constant Summary collapse

ROUTE_TYPES =
['car', 'foot', 'bicycle']
OUTPUT_FORMATS =
['js', 'json', 'gpx']
STATUS_OK =
0
STATUS_ERROR =
1
EARTHS_DIRECTIONS =
["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
TURN_TYPE =
["C", "TL", "TSLL", "TSHL", "TR", "TSLR", "TSHR", "U"]

Instance Attribute Summary

Attributes inherited from Service

#connection, #subdomain

Instance Method Summary collapse

Methods inherited from Service

to_url_params, #url

Instance Method Details

#route(start_point, end_point, transit_points = nil, route_type = 'car', lang = 'en', route_type_modifier = nil) ⇒ Object

Build route. Returns route that was found, instance of CloudMade::Route

  • start_point Starting point

  • end_point Ending point

  • route_type Type of route, e.g. ‘car’, ‘foot’, etc.

  • transit_points List of points route must visit before reaching end. Points are visited in the same order they are specified in the sequence.

  • route_type_modifier Modifier of the route type

  • lang Language code in conformance to ‘ISO 3166-1 alpha-2` standard

  • units Measure units for distance calculation



42
43
44
45
46
47
# File 'lib/cloudmade/routing.rb', line 42

def route(start_point, end_point, transit_points = nil, route_type = 'car', lang = 'en', route_type_modifier = nil)
  transit_points = ",[#{transit_points.map {|point| point.to_latlon}.join(',')}]" if not transit_points == nil
  route_type_modifier = "/#{route_type_modifier}" if not route_type_modifier == nil
  url = "/#{start_point.to_latlon}#{transit_points},#{end_point.to_latlon}/#{route_type}#{route_type_modifier}.js?lang=#{lang}&units=km"
  return Route.new(JSON.parse(connect url))
end

#url_templateObject

:nodoc:



50
51
52
# File 'lib/cloudmade/routing.rb', line 50

def url_template
  return "http://#{@subdomain}.#{@connection.url}/#{@connection.api_key}/api/0.3"
end