gplacesphp/api-client

Modern Google Places API client for PHP

v0.3.0 2018-11-18 09:28 UTC

This package is auto-updated.

Last update: 2024-04-23 16:12:26 UTC


README

Packagist PHP from Packagist Packagist

Build status

Version Linux build Windows build
v1 (master) Travis (.org) branch AppVeyor branch

Introduction

Modern, Object-Oriented, client for using Google's Places API, requires PHP v7.1+. Any PSR-7 (HTTP Message Interface) and PSR-17 (HTTP Factories) implementations is supported (and required). Supports caching by any PSR-16 (simple cache) implementation, also works with any HTTPlug client/adapter.

Installation

composer require gplacesphp/api-client

Usage

This examples uses php-http/guzzle6-adapter as a PSR-18 implementation and zendframework/zend-diactoros as a PSR-7/PSR-17 implementation. Any other PSR-7/PSR-17/PSR-18 implementations are supported. If you don't have them installed you will need to run:

composer require \
    guzzlehttp/guzzle \
    php-http/guzzle6-adapter \
    zendframework/zend-diactoros

Remember to replace <YOUR_API_KEY> with you key.

More usage examples are in examples directory.

Place details

Basic example

<?php

require_once __DIR__ . '/vendor/autoload.php';

$apiKey = '<YOUR_API_KEY>';
$guzzle = new \GuzzleHttp\Client();
$httpClient = new \Http\Adapter\Guzzle6\Client($guzzle);
$requestFactory = new \Zend\Diactoros\RequestFactory();

$client = \GPlacesPhp\ApiClient\Client::create(
    $apiKey,
    $httpClient,
    $requestFactory
);

$placeDetails = $client->placeDetails('ChIJAZ-GmmbMHkcR_NPqiCq-8HI'); // Warsaw

var_dump($placeDetails);

Find place

Basic example

<?php

require_once __DIR__ . '/vendor/autoload.php';

$apiKey = '<YOUR_API_KEY>';
$guzzle = new \GuzzleHttp\Client();
$httpClient = new \Http\Adapter\Guzzle6\Client($guzzle);
$requestFactory = new \Zend\Diactoros\RequestFactory();

$client = \GPlacesPhp\ApiClient\Client::create(
    $apiKey,
    $httpClient,
    $requestFactory
);

$findPlace = $client->findPlace('Warszawa, Polska'); // Warsaw

var_dump($findPlace);

TODOs

Things to do before stable v1 release:

  • Place Details
  • Caching Place Details
  • Places Search
    • Find Place
    • Nearby Search
    • Text Search
  • Caching Places Search
    • Find Place
    • Nearby Search
    • Text Search
  • Place Photos
  • Caching Place Photos
  • Use PSR-18 instead of HTTPlug

License

This package is free software distributed under the terms of the MIT license.