Class: MapTP::Geocoding

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

Overview

Provides a Ruby client to the SOAP interface of the MapTP geocoding services (version 5.1).

Should be initialized for every new geocoding request.

Instance Method Summary collapse

Constructor Details

#initializeGeocoding

Returns a new instance of Geocoding.



9
10
11
12
13
14
15
16
# File 'lib/maptp-service/geocoding.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=Map24Geocoder51"

end

Instance Method Details

#find_coordinates_by_text(query, max_number_of_alternatives = 10, response_language = "EN") ⇒ Object

Searches for addresses and their coordinates that match the provided search query.

Parameters:

query

The search query, e.g. “Times Square, New York”, “Zeil Frankfurt”, “Downing Street 10 London”

max_number_of_alternatives

The max number of alternatives returned by the service (default is 10)

response_language

The language the results shoult be localized (if possible, default is “EN” = English)

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



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
# File 'lib/maptp-service/geocoding.rb', line 30

def find_coordinates_by_text(query, max_number_of_alternatives = 10, response_language = "EN")

  begin

    response = @client.search_free! 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"] = "Map24Geocoder51"
      soap.action = 'searchFree'
      soap.input = 'searchFree'

      soap.body = {

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

        },
        "MapSearchFreeRequest" => {
          "SearchText" => query,
          "MaxNoOfAlternatives" => max_number_of_alternatives,
          "Properties" => {
            "item" =>
              {
                "Key" => "Language",
                "Value"  => response_language,
              }
          }
        }
	
		
      }
	
    end

    MapTP::Parser::GeocodingResult.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