map_monkey 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/map_monkey.rb +89 -0
  2. metadata +46 -0
data/lib/map_monkey.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ class Position
5
+ def lat(strCity, strStreet, strZip)
6
+ # Clean up the string
7
+
8
+ city = URI.encode(strCity)
9
+ #strCity = strCity.gsub(" ", "+")
10
+ #strCity = strCity.gsub("é", "e")
11
+ #strCity = strCity.gsub("ä", "a")
12
+ #strCity = strCity.gsub("å", "a")
13
+ #strCity = strCity.gsub("ö", "o")
14
+
15
+ street = URI.encode(strStreet)
16
+ #strAddress = strAddress.gsub(" ", "+")
17
+ #strAddress = strAddress.gsub("ä", "a")
18
+ #strAddress = strAddress.gsub("å", "a")
19
+ #strAddress = strAddress.gsub("ö", "o")
20
+ #strAdress = strAdress.gsub(".", String.new)
21
+
22
+ zip = URI.encode(strZip)
23
+ #strZip = strZip.gsub(" ", "+")
24
+ #strZip = strZip.gsub(".", String.new)
25
+
26
+ # URL setup
27
+ url = "http://maps.googleapis.com/maps/api/geocode/xml?address=#{ street }#{ zip }#{ city }&sensor=false"
28
+
29
+ #url = URI.parse(strUrl)
30
+ #http = Net::HTTP.new( url.host, url.port )
31
+ xml_data = Net::HTTP.get_response(URI.parse(url)).body
32
+
33
+
34
+ # xml-response
35
+ #data = http.get( url )
36
+ doc = REXML::Document.new(xml_data)
37
+ #doc = Nokogiri::XML(data)
38
+ lat = ""
39
+
40
+ doc.elements.each('GeocodeResponse/result/geometry/location/lat') do |ele|
41
+ lat = ele.text
42
+ end
43
+
44
+ return lat
45
+ end
46
+
47
+ def lng(strCity, strStreet, strZip)
48
+ # Clean up the string
49
+
50
+ city = URI.encode(strCity)
51
+ #strCity = strCity.gsub(" ", "+")
52
+ #strCity = strCity.gsub("é", "e")
53
+ #strCity = strCity.gsub("ä", "a")
54
+ #strCity = strCity.gsub("å", "a")
55
+ #strCity = strCity.gsub("ö", "o")
56
+
57
+ street = URI.encode(strStreet)
58
+ #strAddress = strAddress.gsub(" ", "+")
59
+ #strAddress = strAddress.gsub("ä", "a")
60
+ #strAddress = strAddress.gsub("å", "a")
61
+ #strAddress = strAddress.gsub("ö", "o")
62
+ #strAdress = strAdress.gsub(".", String.new)
63
+
64
+ zip = URI.encode(strZip)
65
+ #strZip = strZip.gsub(" ", "+")
66
+ #strZip = strZip.gsub(".", String.new)
67
+
68
+ # URL setup
69
+ url = "http://maps.googleapis.com/maps/api/geocode/xml?address=#{ street }#{ zip }#{ city }&sensor=false"
70
+
71
+ #url = URI.parse(strUrl)
72
+ #http = Net::HTTP.new( url.host, url.port )
73
+ xml_data = Net::HTTP.get_response(URI.parse(url)).body
74
+
75
+
76
+ # xml-response
77
+ #data = http.get( url )
78
+ doc = REXML::Document.new(xml_data)
79
+ #doc = Nokogiri::XML(data)
80
+
81
+ lng = ""
82
+
83
+ doc.elements.each('result/geometry/location/lng') do |ele|
84
+ lng = ele.text
85
+ end
86
+
87
+ return lng
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map_monkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Khoury
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: It returns your objects lat and long positions on a google map.
15
+ email:
16
+ - ericintheloft@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/map_monkey.rb
22
+ homepage: ''
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Google maps position retriever
46
+ test_files: []