geo_place_search 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geo_place_search.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd582129946f5c7bac0bf6a3325b6d38d3b522d0
|
4
|
+
data.tar.gz: 3795152886c55916857741542ce769e4bea78e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18724d4076c7aa4b8d7cafdf12d84b27b2300ad10e52c98a2480ea40c8ba483bce6a1f216d5b2dbc3f2662336b96b42c00898dbec089b7f774688eb99dfe9a11
|
7
|
+
data.tar.gz: 71e1617ac6b24421fd34fa4b468c9a3ce77b7dd06388de330748b02aec4d290124e28b68677d1cf3c11e4289ef600db6992635ce3a4376bc530ba265a297c532
|
data/lib/geo_place_search.rb
CHANGED
@@ -17,4 +17,28 @@ class GeoPlaceSearch
|
|
17
17
|
end
|
18
18
|
search_results
|
19
19
|
end
|
20
|
+
|
21
|
+
def self.search_places_around_zip(postal_code, keyword, api_key, radius=50000)
|
22
|
+
uri = URI.parse("http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:"+"#{postal_code}"+"&sensor=false")
|
23
|
+
http = Net::HTTP.new(uri.host, 443)
|
24
|
+
http.use_ssl = true
|
25
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
26
|
+
@response = http.request(request)
|
27
|
+
places = JSON.parse(@response.body)
|
28
|
+
place = places["results"].first
|
29
|
+
latitude = place["geometry"]["location"]["lat"]
|
30
|
+
longitude = place["geometry"]["location"]["lng"]
|
31
|
+
|
32
|
+
uri = URI.parse("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{latitude},#{longitude}&radius=#{radius}&keyword=#{keyword}&key=#{api_key}")
|
33
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
34
|
+
http.use_ssl = true
|
35
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
36
|
+
@response = http.request(request)
|
37
|
+
places = JSON.parse(@response.body)
|
38
|
+
search_results = []
|
39
|
+
places["results"].each do |p|
|
40
|
+
search_results << p
|
41
|
+
end
|
42
|
+
search_results
|
43
|
+
end
|
20
44
|
end
|