-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplaces.rb
38 lines (34 loc) · 1.15 KB
/
places.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require_relative 'config'
class GooglePlaceGridSearch
def initialize
CloseEnough::Config::GooglePlaces.each { |k, v| instance_variable_set("@"+k.to_s, v) }
@client = GooglePlaces::Client.new(@api_keys.sample(1).join)
end
def grid(steps)
(@bottom..@top).step( (@top - @bottom) / steps ) do |lat|
(@left..@right).step( (@right - @left) / steps ) do |long|
places = @client.spots(lat, long, :types => @main_types )
places.each do |r|
puts r.name + "\n"
p = Location.new({
:reference => r.reference,
:vicinity => r.vicinity,
:lat => r.lat,
:lng => r.lng,
:name => r.name,
:icon => r.icon,
:types => r.types,
:gid => r.id,
:formatted_phone_number => r.formatted_phone_number,
:formatted_address => r.formatted_address,
:address_components => r.address_components,
:rating => r.rating,
:url => r.url,
:cid => r.cid
})
p.save unless Location.where(:gid => places.first.id).count > 0
end
end
end
end
end