Skip to content

Instantly share code, notes, and snippets.

@gbuesing
Created October 27, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbuesing/a28932ac8dcb64c5bcf6 to your computer and use it in GitHub Desktop.
Save gbuesing/a28932ac8dcb64c5bcf6 to your computer and use it in GitHub Desktop.
GooglePlaces gem spots_by_bounds test
require 'google_places'
api_key = 'key'
# Actually executing stubbed-out spec "should request spots by bounds" from client_spec.rb
# Supplying a bounding box to a text search query does not seem to work, nor is this feature documented:
# https://developers.google.com/places/web-service/search#TextSearchRequests
query = 'pizza'
# Bounds is around city of Nashville TN
bounds = {:start_point => {:lat => '36.06686213257888', :lng => '-86.94168090820312'},
:end_point => {:lat => '36.268635800737876', :lng => '-86.66152954101562'}}
client = GooglePlaces::Client.new api_key
places = client.spots_by_bounds(bounds, :query => query)
puts places.map &:formatted_address
# Returns results form all around the US, none are from bounding box:
# 1415 S Congress Ave, Austin, TX 78704, United States
# 2207 N Clybourn Ave, Chicago, IL 60614, United States
# 439 N Wells St, Chicago, IL 60654, United States
# 1570 Stockton St, San Francisco, CA 94133, United States
# 1853 Solano Ave, Berkeley, CA 94707, United States
# 210 11th St, San Francisco, CA 94103, United States
# 441 Emerson St, Palo Alto, CA 94301, United States
# 400 Valencia St, San Francisco, CA 94103, United States
# 600 N Washington Ave, Minneapolis, MN 55401, United States
# 1919 Hyde St, San Francisco, CA 94109, United States
# 319 N Frances St, Madison, WI 53703, United States
# 6144 Delmar Blvd, St. Louis, MO 63112, United States
# 5646 E Washington St, Indianapolis, IN 46219, United States
# 119 N 4th St, Minneapolis, MN 55401, United States
# 111 Washington St, San Diego, CA 92103, United States
# 2917 Lyndale Ave S, Minneapolis, MN 55408, United States
# 1321 W Grand Ave, Chicago, IL 60642, United States
# 1813 Glenwood Ave, Raleigh, NC 27608, United States
# 846 Divisadero St, San Francisco, CA 94117, United States
# 3463 N Clark St, Chicago, IL 60657, United States
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment