Skip to content

Instantly share code, notes, and snippets.

@xphere
Last active October 12, 2015 12:18
Show Gist options
  • Save xphere/4025638 to your computer and use it in GitHub Desktop.
Save xphere/4025638 to your computer and use it in GitHub Desktop.
Usage of Google\Maps\Geocode
<?php
$geocode = new \Google\Maps\Geocode\GeocodeService();
$cachePath = $this->container->getParameter('kernel.root_dir') . '/../cache';
$cache = new \Doctrine\Common\Cache\FilesystemCache($cachePath);
$cacheAdapter = new \Guzzle\Cache\DoctrineCacheAdapter($cache);
$cachePlugin = new \Guzzle\Plugin\Cache\CachePlugin($cacheAdapter);
$geocode->getClient()->addSubscriber($cachePlugin);
$logPlugin = new \Guzzle\Plugin\Log\LogPlugin(
new \Guzzle\Log\MonologLogAdapter($this->get('logger'))
);
$geocode->getClient()->addSubscriber($logPlugin);
$signer = new \Google\Maps\RequestSigner('clientID', 'vNIXE0xscrmjlyV-12Nj_BvUPaw=');
$signer->attachTo($geocode); // or $geocode->getClient()->addSubscriber($signer);
$request = new \Google\Maps\Geocode\Request\AddressRequest($address);
$request->addComponents(array('country' => 'ES', ));
$request->setLanguage('es');
$result = $geocode->query($request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment