Class: GoogleLocal
Overview
Class for searching with the google local search
Class Method Summary collapse
-
.crawl(term, point, sspn) ⇒ Object
searches a term near point with sspn (span in degrees).
-
.crawl_region(term, point, span, n = 10, &block) ⇒ Object
searches a term near point with sspn (span in degrees) n times n.
-
.search(term, point, sspn) ⇒ Object
searches a term near point with sspn (span in degrees).
-
.search_in_bounding_box(term, bounding_box) ⇒ Object
just searches a term in a bounding box and returns points.
Class Method Details
.crawl(term, point, sspn) ⇒ Object
searches a term near point with sspn (span in degrees)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/google_local.rb', line 30 def self.crawl(term, point, sspn) print " - crawl for '#{term}' at #{point.inspect} within #{sspn.inspect} (" count = 0 4.times do |i| data = get("/uds/GlocalSearch", :query => { :q => term, :start => i * 8, :sll => point.join(","), :sspn => sspn.join(",") }).to_hash if data["responseStatus"] == 200 data["responseData"]["results"].each do |row| yield(row) count += 1 end else raise Exception.new("Error in Google request") end print "." end print ") results: #{count}\n" end |
.crawl_region(term, point, span, n = 10, &block) ⇒ Object
searches a term near point with sspn (span in degrees) n times n
50 51 52 53 54 55 56 57 58 |
# File 'lib/google_local.rb', line 50 def self.crawl_region(term, point, span, n = 10, &block) # :yields: data half_span = span / 2 n.times do |x| n.times do |y| point = [point[0] + x * half_span, point[1] + y * half_span] crawl(term, point, [half_span, half_span], &block) end end end |
.search(term, point, sspn) ⇒ Object
searches a term near point with sspn (span in degrees)
12 13 14 15 16 17 18 19 20 |
# File 'lib/google_local.rb', line 12 def self.search(term, point, sspn) resp = get("/uds/GlocalSearch", :query => { :q => term, :sll => point.join(","), :sspn => sspn.join(",") }) if resp["responseStatus"] == 200 resp["responseData"]["results"] else raise Exception.new("Error in Google request") end end |
.search_in_bounding_box(term, bounding_box) ⇒ Object
just searches a term in a bounding box and returns points
23 24 25 26 27 |
# File 'lib/google_local.rb', line 23 def self.search_in_bounding_box(term, bounding_box) crawl(term, bounding_box.center, bounding_box.sspn).map do |i| MapKit::Point.new(i["lat"].to_f, i["lng"].to_f) end end |