2017 © Pedro Peláez
 

library google-places-api

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

image

varsitynewsnetwork/google-places-api

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

  • Tuesday, July 17, 2018
  • by mrkrstphr
  • Repository
  • 5 Watchers
  • 2 Stars
  • 3,117 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 4 Versions
  • 14 % Grown

The README.md

google-places-api

A mini library to fetch place information out of Google Places API via a text search or a find place request, (*1)

Build Status, (*2)

Usage

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

$results = $service->textSearch('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 textSearch() or findPlace()., (*3)

For instance, if you only wanted the address of the first result:, (*4)

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

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

    return null;
});

The library also ships with some standard formatters:, (*5)

  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:, (*6)

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

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

Which will yield something like:, (*7)

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

The Versions

17/07 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Development Requires

by Mark Boudreau

05/08 2015

v1.1.1

1.1.1.0

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

  Sources   Download

MIT

The Development Requires

by Mark Boudreau

31/07 2015

v1.1.0

1.1.0.0

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

  Sources   Download

MIT

The Development Requires

by Mark Boudreau

30/07 2015

v1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Development Requires

by Mark Boudreau