Class: MapTP::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/maptp-service/routing.rb

Overview

Provides a Ruby client to the SOAP interface of the MapTP routing services.

Should be initialized for every new routing request.

Instance Method Summary collapse

Constructor Details

#initializeRouting

Returns a new instance of Routing.



9
10
11
12
13
14
15
16
# File 'lib/maptp-service/routing.rb', line 9

def initialize

  # Disable log output
  Savon::Request.log = false

  @client = Savon::Client.new "http://#{MapTP::maptp_server}.map24.com/map24/webservices1.5?soap=Map24Routing"

end

Instance Method Details

#find_route_by_coordinates(start, destination) ⇒ Object

Requests a route description for the given coordinates

Parameters:

start

A hash containing, longitude and latitude, e.g. { :lng => 123, :lat => 465}

destination

A hash containing, longitude and latitude, e.g. { :lng => 123, :lat => 465}

Returns either a hash containing the informations or a hash with a key :ERROR containing the error message.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/maptp-service/routing.rb', line 28

def find_route_by_coordinates(start, destination)

  begin

    response = @client.calculate_route! do |soap|

      soap.namespaces["xmlns:SOAP-ENV"] = "http://schemas.xmlsoap.org/soap/envelope/"
      soap.namespaces["xmlns:xsd"] = "http://www.w3.org/2001/XMLSchema"
      soap.namespaces["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
      soap.namespaces["xmlns:wsdl"] = "Map24Routing"
      soap.action = 'calculateRoute'
      soap.input = 'calculateRoute'

      soap.body = {

        "RequestHeader" => {
          "Map24ID" => MapTP::map24_id

        },
        "CalculateRouteRequest" => {
          "Start" => {
            "Coordinate" => {
              "Longitude" => start[:lng] * 60,
              "Latitude" => start[:lat] * 60
            }
		
          },
          "Destination" => {
            "Coordinate" => {
              "Longitude" => destination[:lng] * 60,
              "Latitude" => destination[:lat] * 60
            }
          }
          #,"IgnoreDescription" => true
			
        }
	
		
      }
	
    end

    MapTP::Parser::Route.to_hash(response)

  rescue Savon::SOAPFault => e

    { :ERROR => e.message }


  rescue Savon::HTTPError => e

    { :ERROR => "HTTP Error" }

  rescue SocketError

    { :ERROR => "No HTTP Connection" }

  rescue

    { :ERROR => "Unknown Error" }

  end
  
end