dev-master
9999999-dev https://github.com/xeops/GoogleGeolocationBundleGoogle Geolocaton integration for your Symfony2 project
MIT
The Requires
- php >=7.0
- kriswallsmith/buzz >=0.9
by Darren Rees
geolocation google
Google Geolocaton integration for your Symfony2 project
A Symfony 2 bundle for the Google Geocoding API service., (*1)
Add bundle and Buzz library dependancy to vendor
dir:, (*2)
Using vendors script, (*3)
Add the following to the deps
file:, (*4)
[Buzz] git=git://github.com/kriswallsmith/Buzz.git target=/Buzz [GoogleGeolocationBundle] git=git://github.com/dsyph3r/GoogleGeolocationBundle.git target=/bundles/Google/GeolocationBundle
Run the vendors script:, (*5)
$ php bin/vendors install
Using git submodules:, (*6)
$ git submodule add git://github.com/kriswallsmith/Buzz.git vendor/Buzz $ git submodule add git://github.com/dsyph3r/GoogleGeolocationBundle.git vendor/bundles/Google/GeolocationBundle
Add the Google and Network namespace to your autoloader:, (*7)
// app/autoload.php $loader->registerNamespaces(array( // .. 'Buzz' => __DIR__.'/../vendor/Buzz/lib', 'Google' => __DIR__.'/../vendor/bundles', ));
Add bundle to application kernel:, (*8)
// app/ApplicationKernel.php public function registerBundles() { return array( // ... new Google\GeolocationBundle\GoogleGeolocationBundle(), ); }
The bundle provides a service available via the google_geolocation.geolocation_api
identifier., (*9)
To retrieve the service from the container:, (*10)
$geo = $this->get('google_geolocation.geolocation_api');
To find an address:, (*11)
$geolocationApi = $this->get('google_geolocation.geolocation_api'); $location = $geolocationApi->locateAddress("Wales, UK"); if ($location->getMatches() > 0) { $matches = json_decode($location->getResult(), true); // Get address components [city, country, postcode, etc] for 1st match $components = $location->getAddressComponents(0); // Get LatLng for 2nd match $latLng = $location->getLatLng(1); }
The service can be used in 2 ways:, (*12)
The service is configured by default to not use the caching layer., (*13)
The caching layer provides a cache of previous requests made to the Google Geocoding API to reduce the number of requests required for the service. It also allows limiting of requests made to the service. Both of these features are useful if you heavily use the Google Geocoding API., (*14)
To enable the use of the caching layer you need to configure the service. Update
the config at app/config/config.yml
with the following:, (*15)
services: google_geolocation.geolocation_api: class: %google_geolocation.geolocation_api.class% calls: - [ setEntityManager, [ @doctrine.orm.entity_manager ] ] - [ setDailyLimit, [ %google_geolocation.geolocation_api.daily_limit% ] ] - [ setCacheLifetime, [ %google_geolocation.geolocation_api.cache_lifetime% ] ]
The defaults for the paramaters are as follows:, (*16)
google_geolocation.geolocation_api.daily_limit: 2500 # Daily requests google_geolocation.geolocation_api.cache_lifetime: 24 # Hours
The cache should be cleaned periodically to comply with the Google terms of service (see below), (*17)
Run the following task:, (*18)
$ php app/console google:geolocation:clean-cache
Please respect the terms of service (TOS) specified by Google for use of the Geocoding API., (*19)
The Geocoding API service must only be used in conjunction with a Google Map.
The caching feature provided by the bundle is for temporary caching use in order
to enhance the user experience when using Geocoding (This is permitted by the
TOS). You should run the clean cache task periodically to clean up the cache
values. The lifetime of each Geocoding result can be set via the paramater
google_geolocation.geolocation_api.cache_lifetime
. By default this is set to 24 hours, (*20)
Google Geolocaton integration for your Symfony2 project
MIT
geolocation google