Class: Portero::SearchProvider::GooglePlaces
- Inherits:
-
Object
- Object
- Portero::SearchProvider::GooglePlaces
- Includes:
- Portero::SearchProvider
- Defined in:
- lib/portero/providers/google_places.rb
Instance Method Summary collapse
Methods included from Portero::SearchProvider
Instance Method Details
#parse_results(results) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/portero/providers/google_places.rb', line 22 def parse_results(results) json = JSON.parse(results.body) venues = json["results"] results = [] venues.each do |found_venue| venue = Portero::SearchResult.new venue.id = found_venue["id"] venue.name = found_venue["name"] venue.address = found_venue["formatted_address"] || found_venue["vicinity"] venue.latitude = found_venue["geometry"]["location"]["lat"] venue.longitude = found_venue["geometry"]["location"]["lng"] venue.city = "" venue.state = "" venue.postal_code = "" venue.country = "" venue.category = found_venue["types"].first venue.icon = found_venue["icon"] venue.extra = HashWithIndifferentAccess.new({types: found_venue["types"]}) results << venue end results end |
#search(conn, query, latitude, longitude, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/portero/providers/google_places.rb', line 9 def search(conn, query, latitude, longitude, = {}) params = {} params[:query] = query if query params[:key] = @provider_options[:key] params[:radius] = [:radius] || 10000 params[:location] = [latitude, longitude].join(",") params[:sensor] = false url = query.present? ? "https://maps.googleapis.com/maps/api/place/textsearch/json" : "https://maps.googleapis.com/maps/api/place/search/json" results = conn.get(url, params) parse_results(results) end |