puwnz / google-maps-lib
Library to communicate with Google API
Installs: 1 122
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 2
Requires
- php: >=7.3
- ext-intl: *
- ext-json: *
- monolog/monolog: ^1|^2|^3
- symfony/cache: ^4.0|^5.0|^6.0
- symfony/http-client: ^4.0|^5.0|^6.0
- symfony/property-access: ^5.4|^6.0
- symfony/serializer: ^4.0|^5.0|^6.0
- symfony/validator: ^4.0|^5.0|^6.0
- webmozart/assert: ^1.11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.62
- phpunit/phpunit: ^9.6
- rector/rector: ^1.2
This package is auto-updated.
Last update: 2025-03-12 23:10:36 UTC
README
Overview
The Google Lib project provides a Google Map integration for you PHP 7.3+ project. At this time, just geocode is enable in this lib, because my needs is only on this part, but you can open issues to push your needs.
Installation
To install this lib you can just use composer :
composer require puwnz/google-maps-lib
Integration
<?php use Puwnz\GoogleMapsLib\Constants\SupportedLanguage; use Puwnz\GoogleMapsLib\Constants\SupportedRegion; use Puwnz\GoogleMapsLib\Geocode\QueryBuilder\GeocodeQueryBuilder; use Puwnz\GoogleMapsLib\Geocode\Type\GeocodeComponentQueryType; use Puwnz\GoogleMapsLib\GoogleServiceFactory; use Symfony\Component\Validator\Validation; $geocode = GoogleServiceFactory::create('google-api-key', 'path/log/file', 'http-version'); $components = [ GeocodeComponentQueryType::COUNTRY => 'FR' ]; $geocodeQueryBuilder = new GeocodeQueryBuilder(Validation::createValidator()); $geocodeQueryBuilder->setAddress('10 rue de la Paix, Paris') ->setComponents($components) ->setLanguage(SupportedLanguage::FRENCH) ->setRegion(SupportedRegion::FR) ->setBounds([ 'northeast' => [ 'lat' => 0.0, 'lng' => 1.0 ], 'southwest' => [ 'lat' => -0.0, 'lng' => -1.0 ] ]); $response = $geocode->apply($geocodeQueryBuilder);
The first parameter of factory is required, but the path file for a log and http-version are not.
http-version
should be a float.
Language supported
Google does not accept all language for their apis. You can found all language supported here
If you don't set the language, google can return partial geocoding response for example.
Testing
The bundle is fully unit tested by PHPUnit with a code coverage close to 100%.
Exception
Some exceptions are trigger in this lib, the next list explain in few words why :
- \Puwnz\GoogleMapsLib\Geocode\Exception\GeocodeViolationsException is trigger when you set a wrong data on some builder.
For example, if you not set
lat
key onbounds
in\Puwnz\GoogleMapsLib\Geocode\QueryBuilder\AddressQueryBuilder
Contribute
We love contributors! This is an open source project. If you'd like to contribute, feel free to propose a PR!
License
The Google Map Lib is under the MIT license. For the full copyright and license information, please read the LICENSE file that was distributed with this source code.