map_monkey 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/map_monkey/position.rb +58 -0
- metadata +3 -2
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
module MapMonkey
|
5
|
+
class Position
|
6
|
+
attr_accessor :city, :street, :zip
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@city = URI.encode(options.fetch(:city, ""))
|
10
|
+
@street = URI.encode(options.fetch(:street, ""))
|
11
|
+
@zip = URI.encode(options.fetch(:zip, ""))
|
12
|
+
end
|
13
|
+
|
14
|
+
def city
|
15
|
+
@city
|
16
|
+
end
|
17
|
+
|
18
|
+
def street
|
19
|
+
@street
|
20
|
+
end
|
21
|
+
|
22
|
+
def zip
|
23
|
+
@zip
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
"http://maps.googleapis.com/maps/api/geocode/xml?address=#{street}#{zip}#{city}&sensor=false"
|
28
|
+
end
|
29
|
+
|
30
|
+
def response
|
31
|
+
Net::HTTP.get_response(URI.parse(url)).body
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_lat
|
35
|
+
doc = REXML::Document.new(response)
|
36
|
+
|
37
|
+
doc.elements.each('GeocodeResponse/result/geometry/location/lat') do |ele|
|
38
|
+
@lat = ele.text
|
39
|
+
end
|
40
|
+
|
41
|
+
@lat
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_lng
|
45
|
+
doc = REXML::Document.new(response)
|
46
|
+
|
47
|
+
doc.elements.each('GeocodeResponse/result/geometry/location/lng') do |ele|
|
48
|
+
@lng = ele.text
|
49
|
+
end
|
50
|
+
|
51
|
+
@lng
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_lat_lng
|
55
|
+
[get_lat, get_lng]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06
|
12
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Returns lat and long coordinates from Google Maps API.
|
15
15
|
email:
|
@@ -18,6 +18,7 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- lib/map_monkey/position.rb
|
21
22
|
- lib/map_monkey.rb
|
22
23
|
homepage: https://github.com/eric-khoury/map_monkey
|
23
24
|
licenses: []
|