Giter Site home page Giter Site logo

google_places's Introduction

Google Places

This gem provides a Ruby wrapper around the Google Places API, using HTTParty. At this moment the gem does not support OAuth authentication and will only work with an API key.

Obtaining an API key

To be able to use this gem, you’ll need a Google Places API key. To request an API key, point your browser to code.google.com/apis/console and follow the instructions there. You’ll find your API key on the *API Access* tab under *Simple API Access*.

Installing the gem

To use this gem, install it with gem install google_places or add it to your Gemfile:

gem 'google_places'

And install it with bundle install

Usage

The spot

Each of the API methods below returns a GooglePlaces::Spot or a collection of those. Each of these objects has these attributes:

  • reference: a token to query the Google Places API for more details about the spot

  • vicinity: the street or neighborhood of the spot

  • lat: the latitude of the spot

  • lng: the longitude of the spot

  • name: the name of the spot

  • icon: a URL to the icon of this spot

  • types: array of feature types describing the spot, see list of supported types

  • formatted_phone_number: formatted phone number of the spot (eg (555)555-555)

  • formatted_address: the full address of the spot formatted with commas

  • address_components: the components (eg street address, city, state) of the spot’s address in an array

  • rating: the rating of this spot on Google Places

  • url: the url of this spot on Google Places

Retrieving a list of spots

First register a new Client:

@client = GooglePlaces::Client.new(API_KEY)

Then retrieve a list of spots:

@client.spots(-33.8670522, 151.1957362)

Search by a specific type:

@client.spots(-33.8670522, 151.1957362, :types => 'restaurant')

Search by multiple types:

@client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'])

Search by multiple types but exclude one type:

@client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => 'cafe')

Search by multiple types but exclude multiple types:

@client.spots(-33.8670522, 151.1957362, :types => ['restaurant','food'], :exclude => ['cafe', 'establishment'])

Search by name:

@client.spots(-33.8670522, 151.1957362, :name => 'italian')

Search by name and type:

@client.spots(-33.8670522, 151.1957362, :name => 'italian', :types => 'restaurant')

Retrieving a single spot

First register a new Client:

@client = GooglePlaces::Client.new(API_KEY)

Then retrieve the spot:

@client.spot('CmRYAAA...upoTH3g')

Development

You’re very welcome to add functionality to this gem. To do so, follow these steps:

  1. Fork the project on Github

  2. Clone your own fork on your development machine

  3. Install the dependencies with bundle install

  4. Copy spec/api_key.sample.rb to spec/api_key.rb

  5. Insert your own Google Places API key in spec/api_key.rb

  6. Run the specs with rspec spec

  7. Hackety hack

  8. ???

  9. PROFIT

Feel free to send me a pull request but please make sure your changes are sufficiently covered by RSpec.

Important Note

Concerning the reference field, the Google Places API documentation states:

"You can store this token and use it at any time in future to refresh cached data about this Place,
but the same token is not guaranteed to be returned for any given Place across different searches."

Please be aware that the reference field in spot details may differ from the reference used to retrieve that spot.

google_places's People

Contributors

marceldegraaf avatar rahilsondhi avatar theorganisedmind avatar ironin avatar xavierdutreilh avatar

Watchers

Ty Rauber avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.