Giter Club home page Giter Club logo

php-google-places-api's Introduction

google-places-api

A mini library to fetch place information out of Google Places API via a text search

Usage

$service = new PlaceService(new GuzzleAdapter());
$service->setApiKey('YOUR_KEY_HERE');

$results = $service->search('Van Andel Arena');

Formatters

The concept of formatters are baked in to allow you to easily manipulate the data returned by Google. Simply pass a callable as the second argument to search().

For instance, if you only wanted the address of the first result:

$service = new PlaceService(new GuzzleAdapter());
$service->setApiKey('YOUR_KEY_HERE');

$results = $service->search('Van Andel Arena', function (results) {
    if (count($results)) {
        return $results[0]['formatted_address'];
    }
    
    return null;
});

The library also ships with some standard formatters:

  1. CountryStripperFormatter: Removes the country from the formatted_address
  2. LatLngFormatter: Formats the results as an array of lat, lng, and address.
  3. SingleResultFormatter: Grabs the first result and returns it
  4. CompositeFormatter: Allows for running multiple formatters

Example:

$service = new PlaceService(new GuzzleAdapter());
$service->setApiKey('YOUR_KEY_HERE');

$result = $service->search('Van Andel Arena', new CompositeFormatter([
    new SingleResultFormatter(),
    new CountryStripperFormatter(true),
    new LatLngFormatter(true)
]));

Which will yield something like:

Array
(
    [address] => 130 Fulton West, Grand Rapids, MI 49503
    [lat] => 42.962433
    [lng] => -85.671566
)

php-google-places-api's People

Contributors

mrkrstphr avatar austinsmorris avatar boboudreau avatar

Watchers

James Cloos avatar dani 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.