├── UPGRADE-3.0.md ├── Resources ├── views │ └── Form │ │ ├── place_autocomplete_widget.html.php │ │ └── place_autocomplete_widget.html.twig ├── doc │ ├── service │ │ ├── place │ │ │ ├── index.md │ │ │ ├── photo.md │ │ │ ├── detail.md │ │ │ ├── search.md │ │ │ └── autocomplete.md │ │ ├── index.md │ │ ├── time_zone.md │ │ ├── geocoder.md │ │ ├── elevation.md │ │ ├── direction.md │ │ └── distance_matrix.md │ ├── usage.md │ ├── docker.md │ ├── static_map.md │ ├── installation.md │ ├── map.md │ └── place_autocomplete.md └── config │ ├── service │ ├── geocoder.xml │ ├── time_zone.xml │ ├── direction.xml │ ├── elevation.xml │ ├── place_photo.xml │ ├── place_detail.xml │ ├── place_search.xml │ ├── distance_matrix.xml │ ├── place_autocomplete.xml │ └── serializer.xml │ ├── helper │ ├── utility.xml │ ├── helper.xml │ ├── collector.xml │ ├── renderer.xml │ └── subscriber.xml │ ├── form.xml │ ├── twig.xml │ └── templating.xml ├── phpunit.ci.xml ├── LICENSE ├── DependencyInjection ├── Compiler │ ├── RegisterControlRendererPass.php │ ├── RegisterFormResourcePass.php │ ├── CleanTemplatingPass.php │ ├── RegisterExtendableRendererPass.php │ └── RegisterHelperListenerPass.php ├── Configuration.php └── IvoryGoogleMapExtension.php ├── Templating ├── ApiHelper.php ├── StaticMapHelper.php ├── MapHelper.php └── PlaceAutocompleteHelper.php ├── composer.json ├── IvoryGoogleMapBundle.php ├── Twig ├── ApiExtension.php ├── StaticMapExtension.php ├── MapExtension.php └── PlaceAutocompleteExtension.php ├── UPGRADE-2.0.md ├── README.md ├── CHANGELOG.md └── Form └── Type └── PlaceAutocompleteType.php /UPGRADE-3.0.md: -------------------------------------------------------------------------------- 1 | # UPGRADE 3.0 2 | 3 | ### 2.x to 3.x 4 | 5 | The bundle has mostly been rewrite, so please consider re-reading the documentation for the potential BC breaks in 6 | your code. 7 | -------------------------------------------------------------------------------- /Resources/views/Form/place_autocomplete_widget.html.php: -------------------------------------------------------------------------------- 1 | render($autocomplete, $attr) ?> 2 | 3 | render([$autocomplete]) ?> 4 | 5 | -------------------------------------------------------------------------------- /Resources/views/Form/place_autocomplete_widget.html.twig: -------------------------------------------------------------------------------- 1 | {% block place_autocomplete_widget %} 2 | {{ ivory_google_place_autocomplete(autocomplete, attr) }} 3 | {% if api %} 4 | {{ ivory_google_api([autocomplete]) }} 5 | {% endif %} 6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /Resources/doc/service/place/index.md: -------------------------------------------------------------------------------- 1 | # Google Map Place API Services 2 | 3 | - [Autocomplete](/Resources/doc/service/place/autocomplete.md) 4 | - [Detail](/Resources/doc/service/place/detail.md) 5 | - [Photo](/Resources/doc/service/place/photo.md) 6 | - [Search](/Resources/doc/service/place/search.md) 7 | -------------------------------------------------------------------------------- /Resources/config/service/geocoder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/time_zone.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/direction.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/elevation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/place_photo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/place_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/place_search.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/distance_matrix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/service/place_autocomplete.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/helper/utility.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Resources/config/form.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Resources/doc/service/index.md: -------------------------------------------------------------------------------- 1 | # Google Map API Services 2 | 3 | - [Direction](/Resources/doc/service/direction.md) 4 | - [Distance Matrix](/Resources/doc/service/distance_matrix.md) 5 | - [Elevation](/Resources/doc/service/elevation.md) 6 | - [Geocoder](/Resources/doc/service/geocoder.md) 7 | - [Place](/Resources/doc/service/place/index.md) 8 | - [Autocomplete](/Resources/doc/service/place/autocomplete.md) 9 | - [Detail](/Resources/doc/service/place/detail.md) 10 | - [Photo](/Resources/doc/service/place/photo.md) 11 | - [Search](/Resources/doc/service/place/search.md) 12 | - [Time Zone](/Resources/doc/service/time_zone.md) 13 | -------------------------------------------------------------------------------- /Resources/config/service/serializer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | %kernel.root_dir%/../vendor/egeloen/google-map/src/Service/Serializer 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Resources/doc/usage.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | Before starting, be aware this bundle only integrates the [Ivory Google Map](https://github.com/egeloen/ivory-google-map) 4 | library into your Symfony project. So, start reading it's documentation before reading this one. 5 | 6 | Once you're familiar with the library, you can learn more about the following integrations: 7 | 8 | - [Map](/Resources/doc/map.md) 9 | - [Static Map](/Resources/doc/static_map.md) 10 | - [Place Autocomplete](/Resources/doc/place_autocomplete.md) 11 | - [Services](/Resources/doc/service/index.md) 12 | - [Direction](/Resources/doc/service/direction.md) 13 | - [Distance Matrix](/Resources/doc/service/distance_matrix.md) 14 | - [Elevation](/Resources/doc/service/elevation.md) 15 | - [Geocoder](/Resources/doc/service/geocoder.md) 16 | - [Time Zone](/Resources/doc/service/time_zone.md) 17 | -------------------------------------------------------------------------------- /phpunit.ci.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./Tests 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ./ 18 | 19 | ./Resources 20 | ./Tests 21 | ./vendor 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2017 Eric GELOEN 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 6 | persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/RegisterControlRendererPass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | use Symfony\Component\DependencyInjection\Reference; 17 | 18 | /** 19 | * @author GeLo 20 | */ 21 | class RegisterControlRendererPass implements CompilerPassInterface 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function process(ContainerBuilder $container) 27 | { 28 | $controlManagerRenderer = $container->getDefinition('ivory.google_map.helper.renderer.control.manager'); 29 | 30 | foreach ($container->findTaggedServiceIds('ivory.google_map.helper.renderer.control') as $id => $attributes) { 31 | $controlManagerRenderer->addMethodCall('addRenderer', [new Reference($id)]); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Templating/ApiHelper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Templating; 13 | 14 | use Ivory\GoogleMap\Helper\ApiHelper as BaseApiHelper; 15 | use Symfony\Component\Templating\Helper\Helper; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class ApiHelper extends Helper 21 | { 22 | /** 23 | * @var BaseApiHelper 24 | */ 25 | private $apiHelper; 26 | 27 | /** 28 | * @param BaseApiHelper $apiHelper 29 | */ 30 | public function __construct(BaseApiHelper $apiHelper) 31 | { 32 | $this->apiHelper = $apiHelper; 33 | } 34 | 35 | /** 36 | * @param object[] $objects 37 | * 38 | * @return string 39 | */ 40 | public function render(array $objects) 41 | { 42 | return $this->apiHelper->render($objects); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function getName() 49 | { 50 | return 'ivory_google_api'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Templating/StaticMapHelper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Templating; 13 | 14 | use Ivory\GoogleMap\Helper\StaticMapHelper as BaseStaticMapHelper; 15 | use Ivory\GoogleMap\Map; 16 | use Symfony\Component\Templating\Helper\Helper; 17 | 18 | /** 19 | * @author GeLo 20 | */ 21 | class StaticMapHelper extends Helper 22 | { 23 | /** 24 | * @var BaseStaticMapHelper 25 | */ 26 | private $staticMapHelper; 27 | 28 | /** 29 | * @param BaseStaticMapHelper $staticMapHelper 30 | */ 31 | public function __construct(BaseStaticMapHelper $staticMapHelper) 32 | { 33 | $this->staticMapHelper = $staticMapHelper; 34 | } 35 | 36 | /** 37 | * @param Map $map 38 | * 39 | * @return string 40 | */ 41 | public function render(Map $map) 42 | { 43 | return $this->staticMapHelper->render($map); 44 | } 45 | 46 | /** 47 | * {@inheritdoc} 48 | */ 49 | public function getName() 50 | { 51 | return 'ivory_google_map_static'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "egeloen/google-map-bundle", 3 | "type": "symfony-bundle", 4 | "description": "Provides a google map integration for your Symfony2 Project.", 5 | "keywords": [ "google", "map" ], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Eric GELOEN", 10 | "email": "geloen.eric@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "php": "^5.6|^7.0", 15 | "symfony/framework-bundle": "^2.7|^3.0", 16 | "egeloen/google-map": "^2.0.2" 17 | }, 18 | "require-dev": { 19 | "egeloen/serializer-bundle": "^1.0", 20 | "friendsofphp/php-cs-fixer": "^2.0", 21 | "php-http/cache-plugin": "^1.4", 22 | "php-http/guzzle6-adapter": "^1.0", 23 | "phpunit/phpunit": "^5.4", 24 | "phpunit/phpunit-selenium": "dev-master", 25 | "symfony/cache": "^3.2", 26 | "symfony/form": "^2.7|^3.0", 27 | "symfony/phpunit-bridge": "^2.7|^3.0", 28 | "symfony/templating": "^2.7|^3.0", 29 | "symfony/yaml": "^2.7|^3.0", 30 | "twig/twig": "^1.18" 31 | }, 32 | "autoload": { 33 | "psr-4": { "Ivory\\GoogleMapBundle\\": "" } 34 | }, 35 | "autoload-dev": { 36 | "psr-4": { "Ivory\\Tests\\GoogleMap\\": "vendor/egeloen/google-map/tests" } 37 | }, 38 | "extra": { 39 | "branch-alias": { 40 | "dev-master": "3.0-dev" 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /IvoryGoogleMapBundle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle; 13 | 14 | use Ivory\GoogleMapBundle\DependencyInjection\Compiler\CleanTemplatingPass; 15 | use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterControlRendererPass; 16 | use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterExtendableRendererPass; 17 | use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterFormResourcePass; 18 | use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterHelperListenerPass; 19 | use Symfony\Component\DependencyInjection\ContainerBuilder; 20 | use Symfony\Component\HttpKernel\Bundle\Bundle; 21 | 22 | /** 23 | * @author GeLo 24 | */ 25 | class IvoryGoogleMapBundle extends Bundle 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function build(ContainerBuilder $container) 31 | { 32 | $container 33 | ->addCompilerPass(new CleanTemplatingPass()) 34 | ->addCompilerPass(new RegisterControlRendererPass()) 35 | ->addCompilerPass(new RegisterExtendableRendererPass()) 36 | ->addCompilerPass(new RegisterFormResourcePass()) 37 | ->addCompilerPass(new RegisterHelperListenerPass()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Resources/doc/docker.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | 3 | The most easy way to set up the project is to install [Docker](https://www.docker.com) and 4 | [Docker Composer](https://docs.docker.com/compose/) and build the project. 5 | 6 | ## Configure 7 | 8 | The configuration is shipped with a distribution environment file allowing you to customize your IDE and XDebug 9 | settings as well as your current user/group ID: 10 | 11 | ``` bash 12 | $ cp .env.dist .env 13 | ``` 14 | 15 | **The most important part is the `USER_ID` and `GROUP_ID` which should match your current user/group.** 16 | 17 | ## Build 18 | 19 | Once you have configured your environment, you can build the project: 20 | 21 | ``` bash 22 | $ docker-compose build 23 | ``` 24 | 25 | ## Composer 26 | 27 | Install the dependencies via [Composer](https://getcomposer.org/): 28 | 29 | ``` bash 30 | $ docker-compose run --rm php composer install 31 | ``` 32 | 33 | ## Tests 34 | 35 | To run the test suite, you can use: 36 | 37 | ``` bash 38 | $ docker-compose run --rm php vendor/bin/phpunit 39 | ``` 40 | 41 | If you want to run the test suite against [HHVM](http://hhvm.com/), you can use: 42 | 43 | ``` bash 44 | $ docker-compose run --rm hhvm vendor/bin/phpunit 45 | ``` 46 | 47 | Some tests requires a [Selenium Server](http://www.seleniumhq.org/), you can start it with: 48 | 49 | ``` bash 50 | $ docker-compose up -d 51 | ``` 52 | 53 | ## XDebug 54 | 55 | If you want to use XDebug, make sure you have fully configured your `.env` file and use: 56 | 57 | ``` bash 58 | $ docker-compose run --rm -e XDEBUG=1 php vendor/bin/phpunit 59 | ``` 60 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/RegisterFormResourcePass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class RegisterFormResourcePass implements CompilerPassInterface 21 | { 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function process(ContainerBuilder $container) 26 | { 27 | if ($container->hasParameter($parameter = 'templating.helper.form.resources')) { 28 | $container->setParameter( 29 | $parameter, 30 | array_merge( 31 | ['IvoryGoogleMapBundle:Form'], 32 | $container->getParameter($parameter) 33 | ) 34 | ); 35 | } 36 | 37 | if ($container->hasParameter($parameter = 'twig.form.resources')) { 38 | $container->setParameter( 39 | $parameter, 40 | array_merge( 41 | ['IvoryGoogleMapBundle:Form:place_autocomplete_widget.html.twig'], 42 | $container->getParameter($parameter) 43 | ) 44 | ); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Resources/config/twig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Resources/config/templating.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/CleanTemplatingPass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class CleanTemplatingPass implements CompilerPassInterface 21 | { 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function process(ContainerBuilder $container) 26 | { 27 | if (!$container->hasDefinition('templating.engine.php')) { 28 | $container->removeDefinition('ivory.google_map.templating.api'); 29 | $container->removeDefinition('ivory.google_map.templating.map'); 30 | $container->removeDefinition('ivory.google_map.templating.map.static'); 31 | $container->removeDefinition('ivory.google_map.templating.place_autocomplete'); 32 | } 33 | 34 | if (!$container->hasDefinition('twig')) { 35 | $container->removeDefinition('ivory.google_map.twig.extension.api'); 36 | $container->removeDefinition('ivory.google_map.twig.extension.map'); 37 | $container->removeDefinition('ivory.google_map.twig.extension.map.static'); 38 | $container->removeDefinition('ivory.google_map.twig.extension.place_autocomplete'); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/RegisterExtendableRendererPass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | use Symfony\Component\DependencyInjection\Reference; 17 | 18 | /** 19 | * @author GeLo 20 | */ 21 | class RegisterExtendableRendererPass implements CompilerPassInterface 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function process(ContainerBuilder $container) 27 | { 28 | $tag = 'ivory.google_map.helper.renderer.extendable'; 29 | $extendableRenderer = $container->getDefinition('ivory.google_map.helper.renderer.overlay.extendable'); 30 | 31 | foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) { 32 | foreach ($attributes as $attribute) { 33 | if (!isset($attribute['class'])) { 34 | throw new \RuntimeException(sprintf( 35 | 'No "class" attribute found for the tag "%s" on the service "%s".', 36 | $tag, 37 | $id 38 | )); 39 | } 40 | 41 | $extendableRenderer->addMethodCall('setRenderer', [$attribute['class'], new Reference($id)]); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Twig/ApiExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Twig; 13 | 14 | use Ivory\GoogleMap\Helper\ApiHelper; 15 | 16 | /** 17 | * @author GeLo 18 | */ 19 | class ApiExtension extends \Twig_Extension 20 | { 21 | /** 22 | * @var ApiHelper 23 | */ 24 | private $apiHelper; 25 | 26 | /** 27 | * @param ApiHelper $apiHelper 28 | */ 29 | public function __construct(ApiHelper $apiHelper) 30 | { 31 | $this->apiHelper = $apiHelper; 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public function getFunctions() 38 | { 39 | $functions = []; 40 | 41 | foreach ($this->getMapping() as $name => $method) { 42 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); 43 | } 44 | 45 | return $functions; 46 | } 47 | 48 | /** 49 | * @param object[] $objects 50 | * 51 | * @return string 52 | */ 53 | public function render(array $objects) 54 | { 55 | return $this->apiHelper->render($objects); 56 | } 57 | 58 | /** 59 | * {@inheritdoc} 60 | */ 61 | public function getName() 62 | { 63 | return 'ivory_google_api'; 64 | } 65 | 66 | /** 67 | * @return string[] 68 | */ 69 | private function getMapping() 70 | { 71 | return ['ivory_google_api' => 'render']; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Resources/doc/static_map.md: -------------------------------------------------------------------------------- 1 | # Static Map 2 | 3 | ## Build 4 | 5 | First of all, if you want to render a static map, you will need to build one: 6 | 7 | ``` php 8 | use Ivory\GoogleMap\Map; 9 | 10 | $map = new Map(); 11 | ``` 12 | 13 | Then, you can manipulate it as explained in the library [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/usage.md). 14 | 15 | ## Configuration 16 | 17 | You can configure some global options related to the API in order to update its behavior. 18 | 19 | ### API key 20 | 21 | The API key allows you to bypass Google limitation according to your account plan: 22 | 23 | ``` yaml 24 | ivory_google_map: 25 | static_map: 26 | api_key: ~ 27 | ``` 28 | 29 | ### Api secret 30 | 31 | The API secret allows you to sign your request (even without Premium account): 32 | 33 | ``` yaml 34 | ivory_google_map: 35 | static_map: 36 | business_acount: 37 | secret: ~ 38 | ``` 39 | 40 | ### Business account 41 | 42 | The business account allows you to use Google Premium account: 43 | 44 | ``` yaml 45 | ivory_google_map: 46 | static_map: 47 | business_acount: 48 | client_id: ~ 49 | secret: ~ 50 | channel: ~ 51 | ``` 52 | 53 | ## Render 54 | 55 | Once, your map is ready to be rendered, you should rely on the built-in helpers allowing you to easily render your map 56 | according to your templating engine. 57 | 58 | ### Twig 59 | 60 | If you're using Twig, the most easy way to render a map is: 61 | 62 | ``` twig 63 | 64 | ``` 65 | 66 | ### Php 67 | 68 | If you're using the PHP templating engine, then, the most easy way to render a map is: 69 | 70 | ``` php 71 | 72 | ``` 73 | -------------------------------------------------------------------------------- /Twig/StaticMapExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Twig; 13 | 14 | use Ivory\GoogleMap\Helper\StaticMapHelper; 15 | use Ivory\GoogleMap\Map; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class StaticMapExtension extends \Twig_Extension 21 | { 22 | /** 23 | * @var StaticMapHelper 24 | */ 25 | private $staticMapHelper; 26 | 27 | /** 28 | * @param StaticMapHelper $staticMapHelper 29 | */ 30 | public function __construct(StaticMapHelper $staticMapHelper) 31 | { 32 | $this->staticMapHelper = $staticMapHelper; 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | public function getFunctions() 39 | { 40 | $functions = []; 41 | 42 | foreach ($this->getMapping() as $name => $method) { 43 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); 44 | } 45 | 46 | return $functions; 47 | } 48 | 49 | /** 50 | * @param Map $map 51 | * 52 | * @return string 53 | */ 54 | public function render(Map $map) 55 | { 56 | return $this->staticMapHelper->render($map); 57 | } 58 | 59 | /** 60 | * {@inheritdoc} 61 | */ 62 | public function getName() 63 | { 64 | return 'ivory_google_map_static'; 65 | } 66 | 67 | /** 68 | * @return string[] 69 | */ 70 | private function getMapping() 71 | { 72 | return ['ivory_google_map_static' => 'render']; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Resources/config/helper/helper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Templating/MapHelper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Templating; 13 | 14 | use Ivory\GoogleMap\Helper\MapHelper as BaseMapHelper; 15 | use Ivory\GoogleMap\Map; 16 | use Symfony\Component\Templating\Helper\Helper; 17 | 18 | /** 19 | * @author GeLo 20 | */ 21 | class MapHelper extends Helper 22 | { 23 | /** 24 | * @var BaseMapHelper 25 | */ 26 | private $mapHelper; 27 | 28 | /** 29 | * @param BaseMapHelper $mapHelper 30 | */ 31 | public function __construct(BaseMapHelper $mapHelper) 32 | { 33 | $this->mapHelper = $mapHelper; 34 | } 35 | 36 | /** 37 | * @param Map $map 38 | * @param string[] $attributes 39 | * 40 | * @return string 41 | */ 42 | public function render(Map $map, array $attributes = []) 43 | { 44 | $map->addHtmlAttributes($attributes); 45 | 46 | return $this->mapHelper->render($map); 47 | } 48 | 49 | /** 50 | * @param Map $map 51 | * @param string[] $attributes 52 | * 53 | * @return string 54 | */ 55 | public function renderHtml(Map $map, array $attributes = []) 56 | { 57 | $map->addHtmlAttributes($attributes); 58 | 59 | return $this->mapHelper->renderHtml($map); 60 | } 61 | 62 | /** 63 | * @param Map $map 64 | * 65 | * @return string 66 | */ 67 | public function renderStylesheet(Map $map) 68 | { 69 | return $this->mapHelper->renderStylesheet($map); 70 | } 71 | 72 | /** 73 | * @param Map $map 74 | * 75 | * @return string 76 | */ 77 | public function renderJavascript(Map $map) 78 | { 79 | return $this->mapHelper->renderJavascript($map); 80 | } 81 | 82 | /** 83 | * {@inheritdoc} 84 | */ 85 | public function getName() 86 | { 87 | return 'ivory_google_map'; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Resources/doc/service/place/photo.md: -------------------------------------------------------------------------------- 1 | # Place Photo API 2 | 3 | The Place Photo service, part of the Google Places API Web Service, is a read-only API that allows you to add high 4 | quality photographic content to your application. The Place Photo service gives you access to the millions of photos 5 | stored in the Places and Google+ Local database. When you get place information using a Place Details request, 6 | photo references will be returned for relevant photographic content. The Nearby Search and Text Search requests also 7 | return a single photo reference per place, when relevant. Using the Photo service you can then access the referenced 8 | photos and resize the image to the optimal size for your application. 9 | 10 | To install them, read this [documentation](/Resources/doc/installation.md). 11 | 12 | ## Configuration 13 | 14 | By default, the place photo service is disabled. In order to enable the service, you need to configure it. 15 | 16 | ### Enable 17 | 18 | If you want to enable the place photo service, you can use the following: 19 | 20 | ``` yaml 21 | ivory_google_map: 22 | place_photo: ~ 23 | ``` 24 | 25 | ### Format 26 | 27 | The format allows you to use json/xml format for your http request: 28 | 29 | ``` yaml 30 | ivory_google_map: 31 | place_photo: 32 | format: json 33 | ``` 34 | 35 | ### Api key 36 | 37 | The API key allows you to bypass Google limitation according to your account plan: 38 | 39 | ``` yaml 40 | ivory_google_map: 41 | place_photo: 42 | api_key: ~ 43 | ``` 44 | 45 | ### Business account 46 | 47 | The business account allows you to use Google Premium account: 48 | 49 | ``` yaml 50 | ivory_google_map: 51 | place_photo: 52 | business_account: 53 | client_id: ~ 54 | secret: ~ 55 | channel: ~ 56 | ``` 57 | 58 | ## Usage 59 | 60 | Once you have configured your place photo service, you can fetch it from the container and use it as explained 61 | in the [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/place/photo/place_photo.md). 62 | 63 | ``` php 64 | use Ivory\GoogleMap\Service\Place\Photo\Request\PlacePhotoRequest; 65 | 66 | $request = new PlacePhotoRequest('CnRtAAAATLZNl354RwP_9UKbQ_5P'); 67 | $url = $this->container->get('ivory.google_map.place_photo')->process($request); 68 | ``` 69 | -------------------------------------------------------------------------------- /Templating/PlaceAutocompleteHelper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Templating; 13 | 14 | use Ivory\GoogleMap\Helper\PlaceAutocompleteHelper as BasePlaceAutocompleteHelper; 15 | use Ivory\GoogleMap\Place\Autocomplete; 16 | use Symfony\Component\Templating\Helper\Helper; 17 | 18 | /** 19 | * @author GeLo 20 | */ 21 | class PlaceAutocompleteHelper extends Helper 22 | { 23 | /** 24 | * @var BasePlaceAutocompleteHelper 25 | */ 26 | private $placeAutocompleteHelper; 27 | 28 | /** 29 | * @param BasePlaceAutocompleteHelper $placeAutocompleteHelper 30 | */ 31 | public function __construct(BasePlaceAutocompleteHelper $placeAutocompleteHelper) 32 | { 33 | $this->placeAutocompleteHelper = $placeAutocompleteHelper; 34 | } 35 | 36 | /** 37 | * @param Autocomplete $autocomplete 38 | * @param string[] $attributes 39 | * 40 | * @return string 41 | */ 42 | public function render(Autocomplete $autocomplete, array $attributes = []) 43 | { 44 | $autocomplete->addInputAttributes($attributes); 45 | 46 | return $this->placeAutocompleteHelper->render($autocomplete); 47 | } 48 | 49 | /** 50 | * @param Autocomplete $autocomplete 51 | * @param string[] $attributes 52 | * 53 | * @return string 54 | */ 55 | public function renderHtml(Autocomplete $autocomplete, array $attributes = []) 56 | { 57 | $autocomplete->addInputAttributes($attributes); 58 | 59 | return $this->placeAutocompleteHelper->renderHtml($autocomplete); 60 | } 61 | 62 | /** 63 | * @param Autocomplete $autocomplete 64 | * 65 | * @return string 66 | */ 67 | public function renderJavascript(Autocomplete $autocomplete) 68 | { 69 | return $this->placeAutocompleteHelper->renderJavascript($autocomplete); 70 | } 71 | 72 | /** 73 | * {@inheritdoc} 74 | */ 75 | public function getName() 76 | { 77 | return 'ivory_google_place_autocomplete'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Resources/doc/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | To install the Ivory Google Map bundle, you will need [Composer](http://getcomposer.org). It's a PHP 5.3+ dependency 4 | manager which allows you to declare the dependent libraries your project needs and it will install & autoload them for 5 | you. 6 | 7 | ## Set up Composer 8 | 9 | Composer comes with a simple phar file. To easily access it from anywhere on your system, you can execute: 10 | 11 | ``` bash 12 | $ curl -s https://getcomposer.org/installer | php 13 | $ sudo mv composer.phar /usr/local/bin/composer 14 | ``` 15 | 16 | ## Download the bundle 17 | 18 | Require the library in your `composer.json` file: 19 | 20 | ``` bash 21 | $ composer require egeloen/google-map-bundle 22 | ``` 23 | 24 | ## Download additional libraries 25 | 26 | If you want to use the [Direction](/Resources/doc/service/direction.md), 27 | [Distance Matrix](/Resources//doc/service/distance_matrix.md), [Elevation](/Resources/doc/service/elevation.md), 28 | [Geocoder](/Resources//doc/service/geocoder.md), [Place](/Resources//doc/service/place.md) or 29 | [Time Zone](/Resources/doc/service/time_zone.md) services, you will need an http client and message factory via 30 | [Httplug](http://httplug.io/) which is an http client abstraction library as well as the 31 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 32 | 33 | [Httplug](http://httplug.io/) and [Ivory Serializer](https://github.com/egeloen/ivory-serializer) provide bundles, so 34 | let's install them to ease our life: 35 | 36 | ``` bash 37 | $ composer require egeloen/serializer-bundle 38 | $ composer require php-http/guzzle6-adapter 39 | $ composer require php-http/httplug-bundle 40 | ``` 41 | 42 | Here, I have chosen to use [Guzzle6](http://docs.guzzlephp.org/en/latest/psr7.html) but since Httplug supports the 43 | most popular http clients, you can install your preferred one instead. 44 | 45 | ## Register the bundle 46 | 47 | Then, add the bundle in your `AppKernel`: 48 | 49 | ``` php 50 | // app/AppKernel.php 51 | 52 | public function registerBundles() 53 | { 54 | return [ 55 | // ... 56 | new Ivory\GoogleMapBundle\IvoryGoogleMapBundle(), 57 | 58 | // Optionally 59 | new Ivory\SerializerBundle\IvorySerializerBundle(), 60 | new Http\HttplugBundle\HttplugBundle(), 61 | ]; 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /UPGRADE-2.0.md: -------------------------------------------------------------------------------- 1 | # UPGRADE 2.0 2 | 3 | ### 2.0.2/2.1.2 to 2.0.3/2.1.3 4 | 5 | * The geocoder, directions & distance matrix services have been disabled by default in order to make the 6 | `widop/http-adapter` really optional. 7 | 8 | If you don't provide at least one configuration value (regardless the configuration) for the service you use, you must 9 | explicitely enable it in your configuration file: 10 | 11 | ``` yaml 12 | ivory_google_map: 13 | geocoder: 14 | enabled: true 15 | directions: 16 | enabled: true 17 | distance_matrix: 18 | enabled: true 19 | ``` 20 | 21 | * The buzz dependencies has been removed in favor of the Wid'op http adapter one. This library allows us to use 22 | differents http adapter strategies (including buzz). 23 | 24 | If you're using Services & Symfony >= 2.1, you need to update your `composer.json` file: 25 | 26 | ``` json 27 | { 28 | "require": { 29 | "egeloen/google-map-bundle": "*", 30 | "widop/http-adapter-bundle": "1.1.*" 31 | } 32 | } 33 | ``` 34 | 35 | If you're using Services & Symfony < 2.1, you need to update you `deps` & `app/autoload.php` files: 36 | 37 | ``` 38 | [http-adapter] 39 | git=http://github.com/widop/http-adapter.git 40 | version=1.0.2 41 | 42 | [http-adapter-bundle] 43 | git=http://github.com/widop/WidopHttpAdapterBundle.git 44 | target=bundles/Widop/HttpAdapterBundle 45 | version=1.1.0 46 | ``` 47 | 48 | ``` php 49 | // app/autoload.php 50 | 51 | $loader->registerNamespaces(array( 52 | 'Widop\\HttpAdapter' => __DIR__.'/../vendor/http-adapter/src', 53 | // ... 54 | ); 55 | ``` 56 | 57 | ### 1.1.0 to 1.1.1 58 | 59 | * The event helper service (`ivory_google_map.helper.event`) & configuration parameter 60 | (`ivory_google_map.event.helper_class`) has been removed. 61 | 62 | ### 1.0.0 to 1.1.0 63 | 64 | The business classes have been moved to a dedicated library for reuasibility purpose. If you're using Symfony 2.0.*, 65 | you need to update your `deps` file: 66 | 67 | ``` 68 | [ivory-google-map] 69 | git=http://github.com/egeloen/ivory-google-map.git 70 | ``` 71 | 72 | Autoload the library: 73 | 74 | ``` php 75 | // app/autoload.php 76 | 77 | $loader->registerNamespaces(array( 78 | 'Ivory\\GoogleMap' => __DIR__.'/../vendor/ivory-google-map/src', 79 | // ... 80 | ); 81 | ``` 82 | 83 | Run the vendors script: 84 | 85 | ``` bash 86 | $ php bin/vendors update 87 | ``` 88 | -------------------------------------------------------------------------------- /DependencyInjection/Compiler/RegisterHelperListenerPass.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler; 13 | 14 | use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; 15 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; 17 | use Symfony\Component\DependencyInjection\Reference; 18 | use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; 19 | use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; 20 | 21 | /** 22 | * @author GeLo 23 | */ 24 | class RegisterHelperListenerPass implements CompilerPassInterface 25 | { 26 | /** 27 | * @var string[] 28 | */ 29 | private static $helpers = [ 30 | 'api', 31 | 'map', 32 | 'map.static', 33 | 'place_autocomplete', 34 | ]; 35 | 36 | /** 37 | * @var RegisterListenersPass[] 38 | */ 39 | private $passes = []; 40 | 41 | /** 42 | * {@inheritdoc} 43 | */ 44 | public function __construct() 45 | { 46 | foreach (self::$helpers as $helper) { 47 | $this->passes[] = new RegisterListenersPass( 48 | 'ivory.google_map.helper.'.$helper.'.event_dispatcher', 49 | 'ivory.google_map.helper.'.$helper.'.listener', 50 | 'ivory.google_map.helper.'.$helper.'.subscriber' 51 | ); 52 | } 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function process(ContainerBuilder $container) 59 | { 60 | if (!class_exists(ServiceClosureArgument::class)) { 61 | foreach (self::$helpers as $helper) { 62 | $container 63 | ->getDefinition('ivory.google_map.helper.'.$helper.'.event_dispatcher') 64 | ->setClass(ContainerAwareEventDispatcher::class) 65 | ->addArgument(new Reference('service_container')); 66 | } 67 | } 68 | 69 | foreach ($this->passes as $pass) { 70 | $pass->process($container); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Resources/doc/map.md: -------------------------------------------------------------------------------- 1 | # Map 2 | 3 | ## Build 4 | 5 | First of all, if you want to render a map, you will need to build one: 6 | 7 | ``` php 8 | use Ivory\GoogleMap\Map; 9 | 10 | $map = new Map(); 11 | ``` 12 | 13 | Then, you can manipulate it as explained in the library [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/usage.md). 14 | 15 | ## Configuration 16 | 17 | You can configure some global options related to the API in order to update its behavior. Be aware these options are 18 | shared with the [Place autocomplete](/Resources/doc/place_autocomplete.md). 19 | 20 | ### Debug 21 | 22 | The `debug` option allows to get a nicely formatted output instead of the default output optimized for production: 23 | 24 | ``` yaml 25 | ivory_google_map: 26 | map: 27 | debug: "%kernel.debug%" 28 | ``` 29 | 30 | ### Language 31 | 32 | The language allows you to configure your map language: 33 | 34 | ``` yaml 35 | ivory_google_map: 36 | map: 37 | language: "%locale%" 38 | ``` 39 | 40 | ### API key 41 | 42 | The API key allows you to bypass Google limitation according to your account plan: 43 | 44 | ``` yaml 45 | ivory_google_map: 46 | map: 47 | api_key: ~ 48 | ``` 49 | 50 | ## Render 51 | 52 | Once, your map is ready to be rendered, you should rely on the built-in helpers allowing you to easily render your map 53 | according to your templating engine. 54 | 55 | ### Twig 56 | 57 | If you're using Twig, the most easy way to render a map is: 58 | 59 | ``` twig 60 | {{ ivory_google_map(map) }} 61 | {{ ivory_google_api([map]) }} 62 | ``` 63 | 64 | The available Twig functions are: 65 | 66 | - `ivory_google_api`: Renders the Google API loading. 67 | - `ivory_google_map`: Renders the map container + javascript + stylesheet. 68 | - `ivory_google_map_container`: Renders the map container. 69 | - `ivory_google_map_js`: Renders the map javascript. 70 | - `ivory_google_map_css`: Renders the map stylesheet. 71 | 72 | **Don't forget to always render the Google API loading after rendering your map.** 73 | 74 | ### Php 75 | 76 | If you're using the PHP templating engine, then, the most easy way to render a map is: 77 | 78 | ``` php 79 | render($map) ?> 80 | render([$map]) ?> 81 | ``` 82 | 83 | The available helper methods are: 84 | 85 | - `ivory_google_api::render`: Renders the Google API loading. 86 | - `ivory_google_map::render`: Renders the map container + javascript + stylesheet. 87 | - `ivory_google_map::renderHtml`: Renders the map container. 88 | - `ivory_google_map::renderJavascript`: Renders the map javascript. 89 | - `ivory_google_map::renderStylesheet`: Renders the map stylesheet. 90 | 91 | **Don't forget to always render the Google API loading after rendering your map.** 92 | -------------------------------------------------------------------------------- /Resources/doc/service/time_zone.md: -------------------------------------------------------------------------------- 1 | # Time Zone 2 | 3 | The Google Maps Time Zone API provides a simple interface to request the time zone for a location on the earth, as well 4 | as that location's time offset from UTC. 5 | 6 | ## Dependencies 7 | 8 | The Time Zone API requires an http client and a serializer. The library relies respectively on 9 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 10 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 11 | 12 | To install them, read this [documentation](/Resources/doc/installation.md). 13 | 14 | ## Configuration 15 | 16 | By default, the time zone service is disabled. In order to enable the service, you need to configure it. 17 | 18 | ### Http client and message factory 19 | 20 | The http client and message factory are mandatory. They define which http client and message factory the time zone 21 | service will use for issuing http requests. 22 | 23 | First, configure the [Httplug](http://httplug.io/) bundle. 24 | 25 | ``` yaml 26 | httplug: 27 | classes: 28 | client: Http\Adapter\Guzzle6\Client 29 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 30 | clients: 31 | acme: 32 | factory: httplug.factory.guzzle6 33 | ``` 34 | 35 | Then, configure the Google Map bundle: 36 | 37 | ``` yaml 38 | ivory_google_map: 39 | time_zone: 40 | client: httplug.client.default 41 | message_factory: httplug.message_factory.default 42 | ``` 43 | 44 | ### Format 45 | 46 | The format allows you to use json/xml format for your http request: 47 | 48 | ``` yaml 49 | ivory_google_map: 50 | time_zone: 51 | format: json 52 | ``` 53 | 54 | ### Api key 55 | 56 | The API key allows you to bypass Google limitation according to your account plan: 57 | 58 | ``` yaml 59 | ivory_google_map: 60 | time_zone: 61 | api_key: ~ 62 | ``` 63 | 64 | ### Business account 65 | 66 | The business account allows you to use Google Premium account: 67 | 68 | ``` yaml 69 | ivory_google_map: 70 | time_zone: 71 | business_account: 72 | client_id: ~ 73 | secret: ~ 74 | channel: ~ 75 | ``` 76 | 77 | ## Usage 78 | 79 | Once you have configured your time zone service, you can fetch it from the container and use it as explained in the 80 | [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/time_zone/time_zone.md) 81 | 82 | ``` php 83 | use Ivory\GoogleMap\Base\Coordinate; 84 | use Ivory\GoogleMap\Service\TimeZone\TimeZoneRequest; 85 | 86 | $request = new TimeZoneRequest( 87 | new Coordinate(39.6034810, -119.6822510), 88 | new \DateTime('@1331161200') 89 | ); 90 | 91 | $response = $this->container->get('ivory.google_map.time_zone')->process($request); 92 | ``` 93 | -------------------------------------------------------------------------------- /Resources/doc/service/geocoder.md: -------------------------------------------------------------------------------- 1 | # Geocoder 2 | 3 | Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic 4 | coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. 5 | Additionally, the service allows you to perform the converse operation (turning coordinates into addresses). This 6 | process is known as "reverse geocoding". 7 | 8 | ## Dependencies 9 | 10 | The Geocoder API requires an http client and a serializer. The library relies respectively on 11 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 12 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 13 | 14 | To install them, read this [documentation](/Resources/doc/installation.md). 15 | 16 | ## Configuration 17 | 18 | By default, the geocoder service is disabled. In order to enable the service, you need to configure it. 19 | 20 | ### Http client and message factory 21 | 22 | The http client and message factory are mandatory. They define which http client and message factory the geocoder 23 | service will use for issuing http requests. 24 | 25 | First, configure the [Httplug](http://httplug.io/) bundle. 26 | 27 | ``` yaml 28 | httplug: 29 | classes: 30 | client: Http\Adapter\Guzzle6\Client 31 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 32 | clients: 33 | acme: 34 | factory: httplug.factory.guzzle6 35 | ``` 36 | 37 | Then, configure the Google Map bundle: 38 | 39 | ``` yaml 40 | ivory_google_map: 41 | geocoder: 42 | client: httplug.client.default 43 | message_factory: httplug.message_factory.default 44 | ``` 45 | 46 | ### Format 47 | 48 | The format allows you to use json/xml format for your http request: 49 | 50 | ``` yaml 51 | ivory_google_map: 52 | geocoder: 53 | format: json 54 | ``` 55 | 56 | ### Api key 57 | 58 | The API key allows you to bypass Google limitation according to your account plan: 59 | 60 | ``` yaml 61 | ivory_google_map: 62 | geocoder: 63 | api_key: ~ 64 | ``` 65 | 66 | ### Business account 67 | 68 | The business account allows you to use Google Premium account: 69 | 70 | ``` yaml 71 | ivory_google_map: 72 | geocoder: 73 | business_account: 74 | client_id: ~ 75 | secret: ~ 76 | channel: ~ 77 | ``` 78 | 79 | ## Usage 80 | 81 | Once you have configured your geocoder service, you can fetch it from the container and use it as explained in the 82 | [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/geocoder/geocoder.md) 83 | 84 | ``` php 85 | $request = '1600 Amphitheatre Parkway, Mountain View, CA'; 86 | $response = $this->container->get('ivory.google_map.geocoder')->geocode($request); 87 | ``` 88 | -------------------------------------------------------------------------------- /Twig/MapExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Twig; 13 | 14 | use Ivory\GoogleMap\Helper\MapHelper; 15 | use Ivory\GoogleMap\Map; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class MapExtension extends \Twig_Extension 21 | { 22 | /** 23 | * @var MapHelper 24 | */ 25 | private $mapHelper; 26 | 27 | /** 28 | * @param MapHelper $mapHelper 29 | */ 30 | public function __construct(MapHelper $mapHelper) 31 | { 32 | $this->mapHelper = $mapHelper; 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | public function getFunctions() 39 | { 40 | $functions = []; 41 | 42 | foreach ($this->getMapping() as $name => $method) { 43 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); 44 | } 45 | 46 | return $functions; 47 | } 48 | 49 | /** 50 | * @param Map $map 51 | * @param string[] $attributes 52 | * 53 | * @return string 54 | */ 55 | public function render(Map $map, array $attributes = []) 56 | { 57 | $map->addHtmlAttributes($attributes); 58 | 59 | return $this->mapHelper->render($map); 60 | } 61 | 62 | /** 63 | * @param Map $map 64 | * @param string[] $attributes 65 | * 66 | * @return string 67 | */ 68 | public function renderHtml(Map $map, array $attributes = []) 69 | { 70 | $map->addHtmlAttributes($attributes); 71 | 72 | return $this->mapHelper->renderHtml($map); 73 | } 74 | 75 | /** 76 | * @param Map $map 77 | * 78 | * @return string 79 | */ 80 | public function renderStylesheet(Map $map) 81 | { 82 | return $this->mapHelper->renderStylesheet($map); 83 | } 84 | 85 | /** 86 | * @param Map $map 87 | * 88 | * @return string 89 | */ 90 | public function renderJavascript(Map $map) 91 | { 92 | return $this->mapHelper->renderJavascript($map); 93 | } 94 | 95 | /** 96 | * {@inheritdoc} 97 | */ 98 | public function getName() 99 | { 100 | return 'ivory_google_map'; 101 | } 102 | 103 | /** 104 | * @return string[] 105 | */ 106 | private function getMapping() 107 | { 108 | return [ 109 | 'ivory_google_map' => 'render', 110 | 'ivory_google_map_container' => 'renderHtml', 111 | 'ivory_google_map_css' => 'renderStylesheet', 112 | 'ivory_google_map_js' => 'renderJavascript', 113 | ]; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Resources/doc/service/elevation.md: -------------------------------------------------------------------------------- 1 | # Elevation 2 | 3 | The Google Maps Elevation API provides a simple interface to query locations on the earth for elevation data. 4 | Additionally, you may request sampled elevation data along paths, allowing you to calculate elevation changes along 5 | routes. 6 | 7 | ## Dependencies 8 | 9 | The Elevation API requires an http client and a serializer. The library relies respectively on 10 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 11 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 12 | 13 | To install them, read this [documentation](/Resources/doc/installation.md). 14 | 15 | ## Configuration 16 | 17 | By default, the elevation service is disabled. In order to enable the service, you need to configure it. 18 | 19 | ### Http client and message factory 20 | 21 | The http client and message factory are mandatory. They define which http client and message factory the direction 22 | service will use for issuing http requests. 23 | 24 | First, configure the [Httplug](http://httplug.io/) bundle. 25 | 26 | ``` yaml 27 | httplug: 28 | classes: 29 | client: Http\Adapter\Guzzle6\Client 30 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 31 | clients: 32 | acme: 33 | factory: httplug.factory.guzzle6 34 | ``` 35 | 36 | Then, configure the Google Map bundle: 37 | 38 | ``` yaml 39 | ivory_google_map: 40 | elevation: 41 | client: httplug.client.default 42 | message_factory: httplug.message_factory.default 43 | ``` 44 | 45 | ### Format 46 | 47 | The format allows you to use json/xml format for your http request: 48 | 49 | ``` yaml 50 | ivory_google_map: 51 | elevation: 52 | format: json 53 | ``` 54 | 55 | ### Api key 56 | 57 | The API key allows you to bypass Google limitation according to your account plan: 58 | 59 | ``` yaml 60 | ivory_google_map: 61 | elevation: 62 | api_key: ~ 63 | ``` 64 | 65 | ### Business account 66 | 67 | The business account allows you to use Google Premium account: 68 | 69 | ``` yaml 70 | ivory_google_map: 71 | elevation: 72 | business_account: 73 | client_id: ~ 74 | secret: ~ 75 | channel: ~ 76 | ``` 77 | 78 | ## Usage 79 | 80 | Once you have configured your elevation service, you can fetch it from the container and use it as explained in the 81 | [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/elevation/elevation.md) 82 | 83 | ``` php 84 | use Ivory\GoogleMap\Base\Coordinate; 85 | use Ivory\GoogleMap\Service\Base\Location\CoordinateLocation; 86 | use Ivory\GoogleMap\Service\ELevation\PositionalElevationRequest; 87 | 88 | $request = new PositionalElevationRequest([ 89 | new CoordinateLocation(new Coordinate(40.714728, -73.998672)), 90 | new CoordinateLocation(new Coordinate(-34.397, 150.644)), 91 | ]); 92 | 93 | $response = $this->container->get('ivory.google_map.direction')->route($request); 94 | ``` 95 | -------------------------------------------------------------------------------- /Resources/doc/service/place/detail.md: -------------------------------------------------------------------------------- 1 | # Place Detail API 2 | 3 | The Place Detail service allows you to get detailed response for a place. Once you have a place_id or a reference from 4 | a Place Search, you can request more details about a particular establishment or point of interest by initiating a 5 | Place Details request. A Place Details request returns more comprehensive information about the indicated place such as 6 | its complete address, phone number, user rating and reviews. 7 | 8 | ## Dependencies 9 | 10 | The Place Detail API requires an http client and a serializer. The library relies respectively on 11 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 12 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 13 | 14 | To install them, read this [documentation](/Resources/doc/installation.md). 15 | 16 | ## Configuration 17 | 18 | By default, the place detail service is disabled. In order to enable the service, you need to configure it. 19 | 20 | ### Http client and message factory 21 | 22 | The http client and message factory are mandatory. They define which http client and message factory the place 23 | detail service will use for issuing http requests. 24 | 25 | First, configure the [Httplug](http://httplug.io/) bundle. 26 | 27 | ``` yaml 28 | httplug: 29 | classes: 30 | client: Http\Adapter\Guzzle6\Client 31 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 32 | clients: 33 | acme: 34 | factory: httplug.factory.guzzle6 35 | ``` 36 | 37 | Then, configure the Google Map bundle: 38 | 39 | ``` yaml 40 | ivory_google_map: 41 | place_detail: 42 | client: httplug.client.default 43 | message_factory: httplug.message_factory.default 44 | ``` 45 | 46 | ### Format 47 | 48 | The format allows you to use json/xml format for your http request: 49 | 50 | ``` yaml 51 | ivory_google_map: 52 | place_detail: 53 | format: json 54 | ``` 55 | 56 | ### Api key 57 | 58 | The API key allows you to bypass Google limitation according to your account plan: 59 | 60 | ``` yaml 61 | ivory_google_map: 62 | place_detail: 63 | api_key: ~ 64 | ``` 65 | 66 | ### Business account 67 | 68 | The business account allows you to use Google Premium account: 69 | 70 | ``` yaml 71 | ivory_google_map: 72 | place_detail: 73 | business_account: 74 | client_id: ~ 75 | secret: ~ 76 | channel: ~ 77 | ``` 78 | 79 | ## Usage 80 | 81 | Once you have configured your place detail service, you can fetch it from the container and use it as explained 82 | in the [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/place/detail/place_detail.md). 83 | 84 | ``` php 85 | use Ivory\GoogleMap\Service\Place\Detail\Request\PlaceDetailRequest; 86 | 87 | $request = new PlaceDetailRequest('ChIJN1t_tDeuEmsRUsoyG83frY4'); 88 | $response = $this->container->get('ivory.google_map.place_detail')->process($request); 89 | ``` 90 | -------------------------------------------------------------------------------- /Twig/PlaceAutocompleteExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Twig; 13 | 14 | use Ivory\GoogleMap\Helper\PlaceAutocompleteHelper; 15 | use Ivory\GoogleMap\Place\Autocomplete; 16 | 17 | /** 18 | * @author GeLo 19 | */ 20 | class PlaceAutocompleteExtension extends \Twig_Extension 21 | { 22 | /** 23 | * @var PlaceAutocompleteHelper 24 | */ 25 | private $placeAutocompleteHelper; 26 | 27 | /** 28 | * @param PlaceAutocompleteHelper $placeAutocompleteHelper 29 | */ 30 | public function __construct(PlaceAutocompleteHelper $placeAutocompleteHelper) 31 | { 32 | $this->placeAutocompleteHelper = $placeAutocompleteHelper; 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | public function getFunctions() 39 | { 40 | $functions = []; 41 | 42 | foreach ($this->getMapping() as $name => $method) { 43 | $functions[] = new \Twig_SimpleFunction($name, [$this, $method], ['is_safe' => ['html']]); 44 | } 45 | 46 | return $functions; 47 | } 48 | 49 | /** 50 | * @param Autocomplete $autocomplete 51 | * @param string[] $attributes 52 | * 53 | * @return string 54 | */ 55 | public function render(Autocomplete $autocomplete, array $attributes = []) 56 | { 57 | $autocomplete->addInputAttributes($attributes); 58 | 59 | return $this->placeAutocompleteHelper->render($autocomplete); 60 | } 61 | 62 | /** 63 | * @param Autocomplete $autocomplete 64 | * @param string[] $attributes 65 | * 66 | * @return string 67 | */ 68 | public function renderHtml(Autocomplete $autocomplete, array $attributes = []) 69 | { 70 | $autocomplete->addInputAttributes($attributes); 71 | 72 | return $this->placeAutocompleteHelper->renderHtml($autocomplete); 73 | } 74 | 75 | /** 76 | * @param Autocomplete $autocomplete 77 | * 78 | * @return string 79 | */ 80 | public function renderJavascript(Autocomplete $autocomplete) 81 | { 82 | return $this->placeAutocompleteHelper->renderJavascript($autocomplete); 83 | } 84 | 85 | /** 86 | * {@inheritdoc} 87 | */ 88 | public function getName() 89 | { 90 | return 'ivory_google_place_autocomplete'; 91 | } 92 | 93 | /** 94 | * @return string[] 95 | */ 96 | private function getMapping() 97 | { 98 | return [ 99 | 'ivory_google_place_autocomplete' => 'render', 100 | 'ivory_google_place_autocomplete_container' => 'renderHtml', 101 | 'ivory_google_place_autocomplete_js' => 'renderJavascript', 102 | ]; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Resources/doc/service/direction.md: -------------------------------------------------------------------------------- 1 | # Direction 2 | 3 | The Google Direction API is a service that calculates direction between locations using an HTTP request. You can 4 | search for direction for several modes of transportation, include transit, driving, walking or cycling. Direction 5 | may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") 6 | or as latitude/longitude coordinates. The Direction API can return multi-part direction using a series of waypoints. 7 | 8 | ## Dependencies 9 | 10 | The Direction API requires an http client and a serializer. The library relies respectively on 11 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 12 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 13 | 14 | To install them, read this [documentation](/Resources/doc/installation.md). 15 | 16 | ## Configuration 17 | 18 | By default, the direction service is disabled. In order to enable the service, you need to configure it. 19 | 20 | ### Http client and message factory 21 | 22 | The http client and message factory are mandatory. They define which http client and message factory the direction 23 | service will use for issuing http requests. 24 | 25 | First, configure the [Httplug](http://httplug.io/) bundle. 26 | 27 | ``` yaml 28 | httplug: 29 | classes: 30 | client: Http\Adapter\Guzzle6\Client 31 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 32 | clients: 33 | acme: 34 | factory: httplug.factory.guzzle6 35 | ``` 36 | 37 | Then, configure the Google Map bundle: 38 | 39 | ``` yaml 40 | ivory_google_map: 41 | direction: 42 | client: httplug.client.default 43 | message_factory: httplug.message_factory.default 44 | ``` 45 | 46 | ### Format 47 | 48 | The format allows you to use json/xml format for your http request: 49 | 50 | ``` yaml 51 | ivory_google_map: 52 | direction: 53 | format: json 54 | ``` 55 | 56 | ### Api key 57 | 58 | The API key allows you to bypass Google limitation according to your account plan: 59 | 60 | ``` yaml 61 | ivory_google_map: 62 | direction: 63 | api_key: ~ 64 | ``` 65 | 66 | ### Business account 67 | 68 | The business account allows you to use Google Premium account: 69 | 70 | ``` yaml 71 | ivory_google_map: 72 | direction: 73 | business_account: 74 | client_id: ~ 75 | secret: ~ 76 | channel: ~ 77 | ``` 78 | 79 | ## Usage 80 | 81 | Once you have configured your direction service, you can fetch it from the container and use it as explained in the 82 | [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/direction/direction.md) 83 | 84 | ``` php 85 | use Ivory\GoogleMap\Service\Base\Location\AddressLocation; 86 | use Ivory\GoogleMap\Service\Direction\Request\DirectionRequest; 87 | 88 | $request = new DirectionRequest( 89 | new AddressLocation('New York'), 90 | new AddressLocation('Washington') 91 | ); 92 | 93 | $response = $this->container->get('ivory.google_map.direction')->route($request); 94 | ``` 95 | -------------------------------------------------------------------------------- /Resources/doc/service/place/search.md: -------------------------------------------------------------------------------- 1 | # Place Search API 2 | 3 | The Place Search API Web Service allows you to query for place information on a variety of categories, such as: 4 | establishments, prominent points of interest, geographic locations, and more. You can search for places either by 5 | proximity or a text string. A Place Search returns a list of places along with summary information about each place. 6 | 7 | ## Dependencies 8 | 9 | The Place Autocomplete API requires an http client and a serializer. The library relies respectively on 10 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 11 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 12 | 13 | To install them, read this [documentation](/Resources/doc/installation.md). 14 | 15 | ## Configuration 16 | 17 | By default, the place search service is disabled. In order to enable the service, you need to configure it. 18 | 19 | ### Http client and message factory 20 | 21 | The http client and message factory are mandatory. They define which http client and message factory the place 22 | search service will use for issuing http requests. 23 | 24 | First, configure the [Httplug](http://httplug.io/) bundle. 25 | 26 | ``` yaml 27 | httplug: 28 | classes: 29 | client: Http\Adapter\Guzzle6\Client 30 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 31 | clients: 32 | acme: 33 | factory: httplug.factory.guzzle6 34 | ``` 35 | 36 | Then, configure the Google Map bundle: 37 | 38 | ``` yaml 39 | ivory_google_map: 40 | place_search: 41 | client: httplug.client.default 42 | message_factory: httplug.message_factory.default 43 | ``` 44 | 45 | ### Format 46 | 47 | The format allows you to use json/xml format for your http request: 48 | 49 | ``` yaml 50 | ivory_google_map: 51 | place_search: 52 | format: json 53 | ``` 54 | 55 | ### Api key 56 | 57 | The API key allows you to bypass Google limitation according to your account plan: 58 | 59 | ``` yaml 60 | ivory_google_map: 61 | place_search: 62 | api_key: ~ 63 | ``` 64 | 65 | ### Business account 66 | 67 | The business account allows you to use Google Premium account: 68 | 69 | ``` yaml 70 | ivory_google_map: 71 | place_search: 72 | business_account: 73 | client_id: ~ 74 | secret: ~ 75 | channel: ~ 76 | ``` 77 | 78 | ## Usage 79 | 80 | Once you have configured your place search service, you can fetch it from the container and use it as explained 81 | in the [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/place/search/place_search.md). 82 | 83 | ``` php 84 | use Ivory\GoogleMap\Base\Coordinate; 85 | use Ivory\GoogleMap\Service\Place\Search\Request\NearbyPlaceSearchRequest; 86 | use Ivory\GoogleMap\Service\Place\Search\Request\PlaceSearchRankBy; 87 | 88 | $request = new NearbyPlaceSearchRequest( 89 | new Coordinate(-33.8670522, 151.1957362), 90 | PlaceSearchRankBy::PROMINENCE, 91 | 1000 92 | ); 93 | 94 | $iterator = $this->container->get('ivory.google_map.place_search')->process($request); 95 | ``` 96 | -------------------------------------------------------------------------------- /Resources/doc/service/distance_matrix.md: -------------------------------------------------------------------------------- 1 | # Distance Matrix 2 | 3 | The Google Distance Matrix API is a service that provides travel distance and time for a matrix of origins and 4 | destinations. The information returned is based on the recommended route between start and end points, as calculated 5 | by the Google Maps API, and consists of rows containing duration and distance values for each pair. 6 | 7 | This service does not return detailed route information. Route information can be obtained by passing the desired 8 | single origin and destination to the [Direction API](/Resources/doc/service/direction.md). 9 | 10 | ## Dependencies 11 | 12 | The Distance Matrix API requires an http client and a serializer. The library relies respectively on 13 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 14 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 15 | 16 | To install them, read this [documentation](/Resources/doc/installation.md). 17 | 18 | ## Configuration 19 | 20 | By default, the distance matrix service is disabled. In order to enable the service, you need to configure it. 21 | 22 | ### Http client and message factory 23 | 24 | The http client and message factory are mandatory. They define which http client and message factory the distance 25 | matrix service will use for issuing http requests. 26 | 27 | First, configure the [Httplug](http://httplug.io/) bundle. 28 | 29 | ``` yaml 30 | httplug: 31 | classes: 32 | client: Http\Adapter\Guzzle6\Client 33 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 34 | clients: 35 | acme: 36 | factory: httplug.factory.guzzle6 37 | ``` 38 | 39 | Then, configure the Google Map bundle: 40 | 41 | ``` yaml 42 | ivory_google_map: 43 | distance_matrix: 44 | client: httplug.client.default 45 | message_factory: httplug.message_factory.default 46 | ``` 47 | 48 | ### Format 49 | 50 | The format allows you to use json/xml format for your http request: 51 | 52 | ``` yaml 53 | ivory_google_map: 54 | distance_matrix: 55 | format: json 56 | ``` 57 | 58 | ### Api key 59 | 60 | The API key allows you to bypass Google limitation according to your account plan: 61 | 62 | ``` yaml 63 | ivory_google_map: 64 | distance_matrix: 65 | api_key: ~ 66 | ``` 67 | 68 | ### Business account 69 | 70 | The business account allows you to use Google Premium account: 71 | 72 | ``` yaml 73 | ivory_google_map: 74 | distance_matrix: 75 | business_account: 76 | client_id: ~ 77 | secret: ~ 78 | channel: ~ 79 | ``` 80 | 81 | ## Usage 82 | 83 | Once you have configured your distance matrix service, you can fetch it from the container and use it as explained in 84 | the [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/distance_matrix/distance_matrix.md) 85 | 86 | ``` php 87 | use Ivory\GoogleMap\Service\Base\Location\AddressLocation; 88 | use Ivory\GoogleMap\Service\DistanceMatrix\DistanceMatrixRequest; 89 | 90 | $request = new DistanceMatrixRequest( 91 | [new AddressLocation('Vancouver BC')], 92 | [new AddressLocation('San Francisco')] 93 | ); 94 | 95 | $response = $this->container->get('ivory.google_map.distance_matrix')->process($request); 96 | ``` 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | [![Travis Build Status](https://travis-ci.org/egeloen/IvoryGoogleMapBundle.svg?branch=master)](http://travis-ci.org/egeloen/IvoryGoogleMapBundle) 4 | [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/im2gvivits9qghtk/branch/master?svg=true)](https://ci.appveyor.com/project/egeloen/ivorygooglemapbundle/branch/master) 5 | [![Code Coverage](https://scrutinizer-ci.com/g/egeloen/IvoryGoogleMapBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/egeloen/IvoryGoogleMapBundle/?branch=master) 6 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egeloen/IvoryGoogleMapBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egeloen/IvoryGoogleMapBundle/?branch=master) 7 | [![Dependency Status](http://www.versioneye.com/php/egeloen:google-map-bundle/badge.svg)](http://www.versioneye.com/php/egeloen:google-map-bundle) 8 | 9 | [![Latest Stable Version](https://poser.pugx.org/egeloen/google-map-bundle/v/stable.svg)](https://packagist.org/packages/egeloen/google-map-bundle) 10 | [![Latest Unstable Version](https://poser.pugx.org/egeloen/google-map-bundle/v/unstable.svg)](https://packagist.org/packages/egeloen/google-map-bundle) 11 | [![Total Downloads](https://poser.pugx.org/egeloen/google-map-bundle/downloads.svg)](https://packagist.org/packages/egeloen/google-map-bundle) 12 | [![License](https://poser.pugx.org/egeloen/google-map-bundle/license.svg)](https://packagist.org/packages/egeloen/google-map-bundle) 13 | 14 | The bundle provides an integration of the [Ivory Google Map](https://github.com/egeloen/ivory-google-map) library for 15 | your Symfony2 project. 16 | 17 | ## Documentation 18 | 19 | **You're currently browsing the 3.x documentation, if you're using the 2.x, read 20 | [this documentation](https://github.com/egeloen/IvoryGoogleMapBundle/tree/2.2.1) instead.** 21 | 22 | - [Installation](/Resources/doc/installation.md) 23 | - [Usage](/Resources/doc/usage.md) 24 | - [Map](/Resources/doc/map.md) 25 | - [Static Map](/Resources/doc/static_map.md) 26 | - [Place Autocomplete](/Resources/doc/place_autocomplete.md) 27 | - [Services](/Resources/doc/service/index.md) 28 | - [Direction](/Resources/doc/service/direction.md) 29 | - [Distance Matrix](/Resources/doc/service/distance_matrix.md) 30 | - [Geocoder](/Resources/doc/service/geocoder.md) 31 | - [Place](/Resources/doc/service/place/index.md) 32 | - [Autocomplete](/Resources/doc/service/place/autocomplete.md) 33 | - [Detail](/Resources/doc/service/place/detail.md) 34 | - [Photo](/Resources/doc/service/place/photo.md) 35 | - [Search](/Resources/doc/service/place/search.md) 36 | - [Time Zone](/Resources/doc/service/time_zone.md) 37 | 38 | ## Testing 39 | 40 | The bundle is fully unit tested by [PHPUnit](http://www.phpunit.de/) with a code coverage close to **100%**. To 41 | execute the test suite, check the travis [configuration](/.travis.yml). 42 | 43 | ## Contribute 44 | 45 | We love contributors! Ivory is an open source project. If you'd like to contribute, feel free to propose a PR! You 46 | can follow the [CONTRIBUTING](/CONTRIBUTING.md) file which will explain you how to set up the project. 47 | 48 | ## License 49 | 50 | The Ivory Google Map Bundle is under the MIT license. For the full copyright and license information, please read the 51 | [LICENSE](/LICENSE) file that was distributed with this source code. 52 | -------------------------------------------------------------------------------- /Resources/doc/service/place/autocomplete.md: -------------------------------------------------------------------------------- 1 | # Place Autocomplete API 2 | 3 | The Place Autocomplete service is a web service that returns place predictions in response to an HTTP request. The 4 | request specifies a textual search string and optional geographic bounds. The service can be used to provide 5 | autocomplete functionality for text-based geographic searches, by returning places such as businesses, addresses and 6 | points of interest as a user types. 7 | 8 | The Place Autocomplete service can match on full words as well as substrings. Applications can therefore send queries 9 | as the user types, to provide on-the-fly place predictions. The returned predictions are designed to be presented to the 10 | user to aid them in selecting the desired place. You can send a [Place Details](/Resources/doc/service/place/detail.md) 11 | request for more information about any of the places which are returned. 12 | 13 | ## Dependencies 14 | 15 | The Place Autocomplete API requires an http client and a serializer. The library relies respectively on 16 | [Httplug](http://httplug.io/) which is an http client abstraction library and the 17 | [Ivory Serializer](https://github.com/egeloen/ivory-serializer) which is an advanced (de)-serialization library. 18 | 19 | To install them, read this [documentation](/Resources/doc/installation.md). 20 | 21 | ## Configuration 22 | 23 | By default, the place autocomplete service is disabled. In order to enable the service, you need to configure it. 24 | 25 | ### Http client and message factory 26 | 27 | The http client and message factory are mandatory. They define which http client and message factory the place 28 | autocomplete service will use for issuing http requests. 29 | 30 | First, configure the [Httplug](http://httplug.io/) bundle. 31 | 32 | ``` yaml 33 | httplug: 34 | classes: 35 | client: Http\Adapter\Guzzle6\Client 36 | message_factory: Http\Message\MessageFactory\GuzzleMessageFactory 37 | clients: 38 | acme: 39 | factory: httplug.factory.guzzle6 40 | ``` 41 | 42 | Then, configure the Google Map bundle: 43 | 44 | ``` yaml 45 | ivory_google_map: 46 | place_autocomplete: 47 | client: httplug.client.default 48 | message_factory: httplug.message_factory.default 49 | ``` 50 | 51 | ### Format 52 | 53 | The format allows you to use json/xml format for your http request: 54 | 55 | ``` yaml 56 | ivory_google_map: 57 | place_autocomplete: 58 | format: json 59 | ``` 60 | 61 | ### Api key 62 | 63 | The API key allows you to bypass Google limitation according to your account plan: 64 | 65 | ``` yaml 66 | ivory_google_map: 67 | place_autocomplete: 68 | api_key: ~ 69 | ``` 70 | 71 | ### Business account 72 | 73 | The business account allows you to use Google Premium account: 74 | 75 | ``` yaml 76 | ivory_google_map: 77 | place_autocomplete: 78 | business_account: 79 | client_id: ~ 80 | secret: ~ 81 | channel: ~ 82 | ``` 83 | 84 | ## Usage 85 | 86 | Once you have configured your place autocomplete service, you can fetch it from the container and use it as explained 87 | in the [documentation](https://github.com/egeloen/ivory-google-map/blob/master/doc/service/place/autocomplete/place_autocomplete.md). 88 | 89 | ``` php 90 | use Ivory\GoogleMap\Service\Place\Autocomplete\Request\PlaceAutocompleteRequest; 91 | 92 | $request = new PlaceAutocompleteRequest('Sydney'); 93 | $response = $this->container->get('ivory.google_map.place_autocomplete')->process($request); 94 | ``` 95 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ### 3.0.2 (????-??-??) 4 | 5 | * 8945515 - [Tests] Drop deprecations 6 | * 941f676 - [Travis] Fix tests 7 | * 3deb0c4 - Rename directions.md to direction.md 8 | 9 | ### 3.0.1 (2017-05-27) 10 | 11 | * f3fc045 - Remove deprecations triggered with Symfony 3.3 12 | * 7bf61dd - [Tests] Rely on the new library cache system 13 | * 3410476 - [Doc] Fix place auutocomplete components restriction example 14 | 15 | ### 3.0.0 (2017-02-27) 16 | 17 | * b7cd248 - [Composer] Rely on stable versions 18 | * e136bdc - [Helper] Add static map support 19 | * 9452d96 - Add AppVeyor support 20 | * 1c0bb34 - [Overlay] Add symbol support 21 | * 4a3249e - [Service] Add Place support 22 | * 5896f97 - [Docker] Add HHVM container 23 | * 4a2dbe8 - [Docker] Rely directly on the selenium image 24 | * f113779 - [Git] Fix gitattributes 25 | * e79c4b6 - Add docker support 26 | * 3efa819 - [Composer] Upgrade friendsofphp/php-cs-fixer to 2.x 27 | * dd1c427 - [README] Add note about doc versions 28 | * 11b86cb - [Composer] Upgrade deps 29 | * fd7bba1 - [Scrutinizer] Add configuration file 30 | * f6182ff - [Gitignore] Reorganize by section 31 | * 1f37fed - Add .gitattributes file 32 | * 8c277d9 - Add CONTRIBUTING file 33 | * abbe3c7 - [License] Happy new year 34 | * 9367774 - [Doc] Render multiple place autocompletes 35 | * da0ef82 - Fix info window auto open rendering 36 | * b664856 - Updated link that wasn't working properly 37 | * 4324386 - [Service] Use the same parser for all services 38 | * 5f88711 - [Service] Add suffix to all services 39 | * fc8cc98 - [Doc] Drop 'willdurand/geocoder' dependency 40 | * 85866db - [Direction] Fix according to last egeloen/google-map changes 41 | * 19855f7 - Change bad place autocomplete widget name 42 | * c078775 - [Service] Add elevation support 43 | * 5bd545f - [Map] Add custom/fullscreen control support 44 | * 9587e91 - [Layer] Add auto-zoom support 45 | * 4b0f67f - [Layer] Add heatmap support 46 | * b049e76 - [PlaceAutocomplete] Fix template attributes handling 47 | * 50b3f13 - [Form] Fix place autocomplete resources 48 | * 2ab3cb1 - [3.0] Sync with egeloen/google-map library 49 | * 6e49219 - Update installation.md 50 | 51 | ### 2.2.1 (2014-10-30) 52 | 53 | * bd82776 - [Composer] Refine deps 54 | * 47fbb10 - Rename MarkerImage.xml to MarkerImage.orm.xml 55 | * 03b0110 - [Composer] Upgrade to PSR-4 56 | 57 | ### 2.2.0 (2014-06-17) 58 | 59 | * 2599efe - [Travis] Add Symfony 2.5 + Remove 2.0 branch 60 | * bf48170 - Replace deprecated twig features + Fix PHPDoc + Bump phpunit to ~4.0 + Bump twig to ~1.12 61 | * fdffec8 - Add coveralls support 62 | * b2569ba - Fix Geocoder provider documentation 63 | * c2d25a7 - [Helper] Allow to render the map in a single call 64 | * d69152a - [Places] Add component restrictions support 65 | * e6cf9ce - Update new year 66 | * 69e8426 - Deprecate Symfony 2.0 67 | 68 | ### 2.0.3 - 2.1.3 (2013-12-12) 69 | 70 | * 2ffb7cd - [Travis] Simplify matrix + Add Symfony 2.4 to the build 71 | * 1c161c6 - Make widop/http-adapter-bundle really optional 72 | * df9d815 - [Service] Add business account support 73 | * 0512906 - [Service] Replace kriswallsmith/buzz by widop/http-adapter 74 | 75 | ### 2.0.2 - 2.1.2 (2013-10-09) 76 | 77 | * 01d5583 - Add info box support 78 | * a871d55 - [PlacesAutocompleteType] Fix missing name html attribute + use text as parent type 79 | 80 | ### 2.0.1 - 2.1.1 (2013-08-22) 81 | 82 | * 034e312 - [Overlays] Add marker cluster support 83 | * fe226ae - Add Places autocomplete support 84 | * a619815 - Fix PHP template service by making it public 85 | 86 | ### 2.0.0 (2013-06-07) 87 | 88 | * db9c9c2 - Add Distance Matrix support 89 | * b151380 - Add PHP template support 90 | * d22d5d3 - [Travis] Use --prefer-source to avoid random build fail 91 | * 83d85e3 - [DI] Use Extension processConfiguration method 92 | 93 | ### 1.1.1 (2013-04-10) 94 | 95 | * c662180 - [Helper] Add JS container 96 | * 54ac124 - PSR2 compatibility 97 | * df4265d - Refactor according to helper renaming 98 | 99 | ### 1.1.0 (2012-03-13) 100 | 101 | * 2c13c5b - Remove prototyped services 102 | * 76b0a46 - [Geocoder][Request] Add language support 103 | * bbf251f - Allow to override all business classes & helpers 104 | * f82a0d4 - [Directions] Add language parameter to the request 105 | * a02d698 - [EventListener] Fix fake request listener registration 106 | * de0c9e6 - [Tests] Fix code coverage 107 | * 86b9ad3 - [Entity] Fix map pre persist 108 | * 4c7674d - Extract business class + Fix CS 109 | 110 | ### 1.0.0 (2012-04-25) 111 | -------------------------------------------------------------------------------- /Form/Type/PlaceAutocompleteType.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\Form\Type; 13 | 14 | use Ivory\GoogleMap\Base\Bound; 15 | use Ivory\GoogleMap\Place\Autocomplete; 16 | use Symfony\Component\Form\AbstractType; 17 | use Symfony\Component\Form\Extension\Core\Type\TextType; 18 | use Symfony\Component\Form\FormBuilderInterface; 19 | use Symfony\Component\Form\FormInterface; 20 | use Symfony\Component\Form\FormView; 21 | use Symfony\Component\OptionsResolver\OptionsResolver; 22 | 23 | /** 24 | * @author GeLo 25 | */ 26 | class PlaceAutocompleteType extends AbstractType 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function buildForm(FormBuilderInterface $builder, array $options) 32 | { 33 | $autocomplete = new Autocomplete(); 34 | 35 | if ($options['variable'] !== null) { 36 | $autocomplete->setVariable($options['variable']); 37 | } 38 | 39 | if (!empty($options['components'])) { 40 | $autocomplete->setComponents($options['components']); 41 | } 42 | 43 | if ($options['bound'] !== null) { 44 | $autocomplete->setBound($options['bound']); 45 | } 46 | 47 | $autocomplete->getEventManager()->setDomEvents($options['dom_events']); 48 | $autocomplete->getEventManager()->setDomEventsOnce($options['dom_events_once']); 49 | $autocomplete->getEventManager()->setEvents($options['events']); 50 | $autocomplete->getEventManager()->setEventsOnce($options['events_once']); 51 | 52 | if (!empty($options['types'])) { 53 | $autocomplete->setTypes($options['types']); 54 | } 55 | 56 | if (!empty($options['libraries'])) { 57 | $autocomplete->setLibraries($options['libraries']); 58 | } 59 | 60 | $builder->setAttribute('autocomplete', $autocomplete); 61 | } 62 | 63 | /** 64 | * {@inheritdoc} 65 | */ 66 | public function finishView(FormView $view, FormInterface $form, array $options) 67 | { 68 | $autocomplete = $form->getConfig()->getAttribute('autocomplete'); 69 | $autocomplete->setInputId($view->vars['id']); 70 | $autocomplete->setValue(!empty($view->vars['value']) ? $view->vars['value'] : null); 71 | $autocomplete->setInputAttribute('name', $view->vars['full_name']); 72 | 73 | $view->vars['api'] = $options['api']; 74 | $view->vars['autocomplete'] = $autocomplete; 75 | } 76 | 77 | /** 78 | * {@inheritdoc} 79 | */ 80 | public function configureOptions(OptionsResolver $resolver) 81 | { 82 | $resolver 83 | ->setDefaults([ 84 | 'variable' => null, 85 | 'components' => [], 86 | 'bound' => null, 87 | 'dom_events' => [], 88 | 'dom_events_once' => [], 89 | 'events' => [], 90 | 'events_once' => [], 91 | 'types' => [], 92 | 'libraries' => [], 93 | 'api' => true, 94 | ]) 95 | ->addAllowedTypes('variable', ['string', 'null']) 96 | ->addAllowedTypes('bound', [Bound::class, 'null']) 97 | ->addAllowedTypes('components', 'array') 98 | ->addAllowedTypes('dom_events', 'array') 99 | ->addAllowedTypes('dom_events_once', 'array') 100 | ->addAllowedTypes('events', 'array') 101 | ->addAllowedTypes('events_once', 'array') 102 | ->addAllowedTypes('types', 'array') 103 | ->addAllowedTypes('libraries', 'array') 104 | ->addAllowedTypes('api', 'bool'); 105 | } 106 | 107 | /** 108 | * {@inheritdoc} 109 | */ 110 | public function getParent() 111 | { 112 | return method_exists(AbstractType::class, 'getBlockPrefix') ? TextType::class : 'text'; 113 | } 114 | 115 | /** 116 | * {@inheritdoc} 117 | */ 118 | public function getBlockPrefix() 119 | { 120 | return 'place_autocomplete'; 121 | } 122 | 123 | /** 124 | * {@inheritdoc} 125 | */ 126 | public function getName() 127 | { 128 | return $this->getBlockPrefix(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection; 13 | 14 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; 15 | use Symfony\Component\Config\Definition\Builder\NodeDefinition; 16 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; 17 | use Symfony\Component\Config\Definition\ConfigurationInterface; 18 | 19 | /** 20 | * @author GeLo 21 | */ 22 | class Configuration implements ConfigurationInterface 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function getConfigTreeBuilder() 28 | { 29 | $treeBuilder = $this->createTreeBuilder(); 30 | $children = $treeBuilder->root('ivory_google_map') 31 | ->children() 32 | ->append($this->createMapNode()) 33 | ->append($this->createStaticMapNode()); 34 | 35 | $services = [ 36 | 'direction' => true, 37 | 'distance_matrix' => true, 38 | 'elevation' => true, 39 | 'geocoder' => true, 40 | 'place_autocomplete' => true, 41 | 'place_detail' => true, 42 | 'place_photo' => false, 43 | 'place_search' => true, 44 | 'time_zone' => true, 45 | ]; 46 | 47 | foreach ($services as $service => $http) { 48 | $children->append($this->createServiceNode($service, $http)); 49 | } 50 | 51 | return $treeBuilder; 52 | } 53 | 54 | /** 55 | * @return ArrayNodeDefinition 56 | */ 57 | private function createMapNode() 58 | { 59 | return $this->createNode('map') 60 | ->addDefaultsIfNotSet() 61 | ->children() 62 | ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() 63 | ->scalarNode('language')->defaultValue('%locale%')->end() 64 | ->scalarNode('api_key')->end() 65 | ->end(); 66 | } 67 | 68 | /** 69 | * @return ArrayNodeDefinition 70 | */ 71 | private function createStaticMapNode() 72 | { 73 | return $this->createNode('static_map') 74 | ->addDefaultsIfNotSet() 75 | ->children() 76 | ->scalarNode('api_key')->end() 77 | ->append($this->createBusinessAccountNode(false)) 78 | ->end(); 79 | } 80 | 81 | /** 82 | * @param string $service 83 | * @param bool $http 84 | * 85 | * @return ArrayNodeDefinition 86 | */ 87 | private function createServiceNode($service, $http) 88 | { 89 | $node = $this->createNode($service); 90 | $children = $node 91 | ->children() 92 | ->scalarNode('api_key')->end() 93 | ->append($this->createBusinessAccountNode(true)); 94 | 95 | if ($http) { 96 | $children 97 | ->scalarNode('client') 98 | ->isRequired() 99 | ->cannotBeEmpty() 100 | ->end() 101 | ->scalarNode('message_factory') 102 | ->isRequired() 103 | ->cannotBeEmpty() 104 | ->end() 105 | ->scalarNode('format')->end(); 106 | } else { 107 | $node 108 | ->beforeNormalization() 109 | ->ifNull() 110 | ->then(function () { 111 | return []; 112 | }) 113 | ->end(); 114 | } 115 | 116 | return $node; 117 | } 118 | 119 | /** 120 | * @param bool $service 121 | * 122 | * @return ArrayNodeDefinition 123 | */ 124 | private function createBusinessAccountNode($service) 125 | { 126 | $node = $this->createNode('business_account'); 127 | $clientIdNode = $node->children() 128 | ->scalarNode('secret') 129 | ->isRequired() 130 | ->cannotBeEmpty() 131 | ->end() 132 | ->scalarNode('channel')->end() 133 | ->scalarNode('client_id'); 134 | 135 | if ($service) { 136 | $clientIdNode 137 | ->isRequired() 138 | ->cannotBeEmpty(); 139 | } 140 | 141 | return $node; 142 | } 143 | 144 | /** 145 | * @param string $name 146 | * @param string $type 147 | * 148 | * @return ArrayNodeDefinition|NodeDefinition 149 | */ 150 | private function createNode($name, $type = 'array') 151 | { 152 | return $this->createTreeBuilder()->root($name, $type); 153 | } 154 | 155 | /** 156 | * @return TreeBuilder 157 | */ 158 | private function createTreeBuilder() 159 | { 160 | return new TreeBuilder(); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Resources/doc/place_autocomplete.md: -------------------------------------------------------------------------------- 1 | # Place Autocomplete 2 | 3 | If you want to use the place autocomplete feature in your Symfony project, the easiest way is to rely on the built-in 4 | for type shipped with the bundle. 5 | 6 | ``` php 7 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 8 | 9 | $builder->add('field', PlaceAutocompleteType::class); 10 | ``` 11 | 12 | The form type supports options which allows you to configure the places autocomplete. 13 | 14 | ## Configure variable 15 | 16 | A variable is automatically generated when creating an autocomplete but if you want to update it, you can use: 17 | 18 | ``` php 19 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 20 | 21 | $builder->add('field', PlaceAutocompleteType::class, [ 22 | 'variable' => 'place_autocomplete', 23 | ]); 24 | ``` 25 | 26 | ## Configure components 27 | 28 | If you want to restrict the autocomplete to components, you can use: 29 | 30 | ``` php 31 | use Ivory\GoogleMap\Place\AutocompleteComponentType; 32 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 33 | 34 | $builder->add('field', PlaceAutocompleteType::class, [ 35 | 'components' => [AutocompleteComponentType::COUNTRY => 'fr'], 36 | ]); 37 | ``` 38 | 39 | ## Configure bound 40 | 41 | If you want to restrict the search area, you can configure a bound: 42 | 43 | ``` php 44 | use Ivory\GoogleMap\Base\Bound; 45 | use Ivory\GoogleMap\Base\Coordinate; 46 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 47 | 48 | $builder->add('field', PlaceAutocompleteType::class, [ 49 | 'bound' => new Bound( 50 | new Coordinate(-2.1, -3.9), 51 | new Coordinate(2.6, 1.4) 52 | ), 53 | ]); 54 | ``` 55 | 56 | ## Configure events 57 | 58 | Javascript within the browser is event driven, meaning that Javascript responds to interactions by generating events, 59 | and expects a program to listen to interesting events. 60 | 61 | Before reading this part of the documentation, you should familiarize yourself with the [Event](https://github.com/egeloen/ivory-google-map/blob/master/doc/event.md). 62 | 63 | ### Dom events 64 | 65 | If you want to attach dom events to your place autocomplete: 66 | 67 | ``` php 68 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 69 | 70 | $builder->add('field', PlaceAutocompleteType::class, [ 71 | 'dom_events' => [$event], 72 | ]); 73 | ``` 74 | 75 | ### Dom events once 76 | 77 | If you want to attach dom events once to your place autocomplete: 78 | 79 | ``` php 80 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 81 | 82 | $builder->add('field', PlaceAutocompleteType::class, [ 83 | 'dom_events_once' => [$event], 84 | ]); 85 | ``` 86 | 87 | ### Events 88 | 89 | If you want to attach events to your place autocomplete: 90 | 91 | ``` php 92 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 93 | 94 | $builder->add('field', PlaceAutocompleteType::class, [ 95 | 'events' => [$event], 96 | ]); 97 | ``` 98 | 99 | ### Events once 100 | 101 | If you want to attach events once to your place autocomplete: 102 | 103 | ``` php 104 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 105 | 106 | $builder->add('field', PlaceAutocompleteType::class, [ 107 | 'events_once' => [$event], 108 | ]); 109 | ``` 110 | 111 | ## Configure types 112 | 113 | If you want to restrict places types, you can use: 114 | 115 | ``` php 116 | use Ivory\GoogleMap\Place\AutocompleteType; 117 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 118 | 119 | $builder->add('field', PlaceAutocompleteType::class, [ 120 | 'types' => PlaceAutocompleteType::ESTABLISMENT, 121 | ]); 122 | ``` 123 | 124 | ## Configure libraries 125 | 126 | Sometimes, you want to use the autocomplete & other Google Map related libraries. The library provides many 127 | integrations but not all of them. If you need a custom library (for example `drawing`), you can use: 128 | 129 | ``` php 130 | use Ivory\GoogleMap\Place\AutocompleteType; 131 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 132 | 133 | $builder->add('field', PlaceAutocompleteType::class, [ 134 | 'libraries' => ['drawing'], 135 | ]); 136 | ``` 137 | 138 | ## Configure api 139 | 140 | In order to make everything automatic, the bundle automatically renders the Google API loading when rendering a place 141 | autocomplete. If you want to disable this behavior, you can use: 142 | 143 | ``` php 144 | use Ivory\GoogleMap\Place\AutocompleteType; 145 | use Ivory\GoogleMapBundle\Form\Type\PlaceAutocompleteType; 146 | 147 | $builder 148 | ->add('field1', PlaceAutocompleteType::class, [ 149 | 'api' => false, 150 | ]) 151 | ->add('field2', PlaceAutocompleteType::class, [ 152 | 'api' => false, 153 | ]); 154 | ``` 155 | 156 | Disabling the API loading is also very useful if you want to render multiple autocompletes since the API loading can 157 | only be triggered once. In order to load it once, you can use the following: 158 | 159 | ``` twig 160 | {% block javascripts %} 161 | {{ parent() }} 162 | {{ ivory_google_api([ 163 | form.field1.vars['autocomplete'], 164 | form.field2.vars['autocomplete'] 165 | ]) }} 166 | {% endblock %} 167 | ``` 168 | -------------------------------------------------------------------------------- /DependencyInjection/IvoryGoogleMapExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please read the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Ivory\GoogleMapBundle\DependencyInjection; 13 | 14 | use Ivory\GoogleMap\Service\BusinessAccount; 15 | use Symfony\Component\Config\FileLocator; 16 | use Symfony\Component\Config\Loader\LoaderInterface; 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; 18 | use Symfony\Component\DependencyInjection\Definition; 19 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; 20 | use Symfony\Component\DependencyInjection\Reference; 21 | use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; 22 | 23 | /** 24 | * @author GeLo 25 | */ 26 | class IvoryGoogleMapExtension extends ConfigurableExtension 27 | { 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function loadInternal(array $config, ContainerBuilder $container) 32 | { 33 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 34 | 35 | $resources = [ 36 | 'form', 37 | 'helper/collector', 38 | 'helper/helper', 39 | 'helper/renderer', 40 | 'helper/subscriber', 41 | 'helper/utility', 42 | 'templating', 43 | 'twig', 44 | ]; 45 | 46 | foreach ($resources as $resource) { 47 | $loader->load($resource.'.xml'); 48 | } 49 | 50 | $this->loadMapConfig($config['map'], $container); 51 | $this->loadStaticMapConfig($config['static_map'], $container); 52 | $this->loadServicesConfig($config, $container, $loader); 53 | } 54 | 55 | /** 56 | * @param mixed[] $config 57 | * @param ContainerBuilder $container 58 | */ 59 | private function loadMapConfig(array $config, ContainerBuilder $container) 60 | { 61 | $container 62 | ->getDefinition('ivory.google_map.helper.renderer.loader') 63 | ->addArgument($config['language']); 64 | 65 | if ($config['debug']) { 66 | $container 67 | ->getDefinition('ivory.google_map.helper.formatter') 68 | ->addArgument($config['debug']); 69 | } 70 | 71 | if (isset($config['api_key'])) { 72 | $container 73 | ->getDefinition('ivory.google_map.helper.renderer.loader') 74 | ->addArgument($config['api_key']); 75 | } 76 | } 77 | 78 | /** 79 | * @param mixed[] $config 80 | * @param ContainerBuilder $container 81 | */ 82 | private function loadStaticMapConfig(array $config, ContainerBuilder $container) 83 | { 84 | if (isset($config['api_key'])) { 85 | $container 86 | ->getDefinition('ivory.google_map.helper.subscriber.static.key') 87 | ->addArgument($config['api_key']); 88 | } 89 | 90 | if (isset($config['business_account'])) { 91 | $businessAccount = $config['business_account']; 92 | 93 | $container 94 | ->getDefinition('ivory.google_map.helper.map.static') 95 | ->addArgument(isset($businessAccount['secret']) ? $businessAccount['secret'] : null) 96 | ->addArgument(isset($businessAccount['client_id']) ? $businessAccount['client_id'] : null) 97 | ->addArgument(isset($businessAccount['channel']) ? $businessAccount['channel'] : null); 98 | } 99 | } 100 | 101 | /** 102 | * @param mixed[] $config 103 | * @param ContainerBuilder $container 104 | * @param LoaderInterface $loader 105 | */ 106 | private function loadServicesConfig(array $config, ContainerBuilder $container, LoaderInterface $loader) 107 | { 108 | $services = [ 109 | 'direction' => true, 110 | 'distance_matrix' => true, 111 | 'elevation' => true, 112 | 'geocoder' => true, 113 | 'place_autocomplete' => true, 114 | 'place_detail' => true, 115 | 'place_photo' => false, 116 | 'place_search' => true, 117 | 'time_zone' => true, 118 | ]; 119 | 120 | foreach ($services as $service => $http) { 121 | if (isset($config[$service])) { 122 | $this->loadServiceConfig($service, $config[$service], $container, $loader, $http); 123 | } 124 | } 125 | } 126 | 127 | /** 128 | * @param string $service 129 | * @param mixed[] $config 130 | * @param ContainerBuilder $container 131 | * @param LoaderInterface $loader 132 | * @param bool $http 133 | */ 134 | private function loadServiceConfig( 135 | $service, 136 | array $config, 137 | ContainerBuilder $container, 138 | LoaderInterface $loader, 139 | $http = true 140 | ) { 141 | $loader->load('service/'.$service.'.xml'); 142 | $definition = $container->getDefinition($serviceName = 'ivory.google_map.'.$service); 143 | 144 | if ($http) { 145 | $loader->load('service/serializer.xml'); 146 | 147 | $definition 148 | ->addArgument(new Reference($config['client'])) 149 | ->addArgument(new Reference($config['message_factory'])) 150 | ->addArgument(new Reference('ivory.serializer')); 151 | } 152 | 153 | if ($http && isset($config['format'])) { 154 | $definition->addMethodCall('setFormat', [$config['format']]); 155 | } 156 | 157 | if (isset($config['api_key'])) { 158 | $definition->addMethodCall('setKey', [$config['api_key']]); 159 | } 160 | 161 | if (isset($config['business_account'])) { 162 | $businessAccountConfig = $config['business_account']; 163 | 164 | $container->setDefinition( 165 | $businessAccountName = $serviceName.'.business_account', 166 | new Definition(BusinessAccount::class, [ 167 | $businessAccountConfig['client_id'], 168 | $businessAccountConfig['secret'], 169 | isset($businessAccountConfig['channel']) ? $businessAccountConfig['channel'] : null, 170 | ]) 171 | ); 172 | 173 | $definition->addMethodCall('setBusinessAccount', [new Reference($businessAccountName)]); 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /Resources/config/helper/collector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 54 | 55 | 59 | 60 | 64 | 65 | 69 | 70 | 74 | 75 | 79 | 80 | 84 | 85 | 89 | 90 | 94 | 95 | 99 | 100 | 104 | 105 | 109 | 110 | 111 | 112 | 116 | 117 | 118 | 119 | 123 | 124 | 125 | 126 | 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 | 144 | 145 | 149 | 150 | 151 | 152 | 156 | 157 | 161 | 162 | 166 | 167 | 171 | 172 | 173 | 174 | 175 | 179 | 180 | 184 | 185 | 186 | 187 | 191 | 192 | 196 | 197 | 201 | 202 | 206 | 207 | 211 | 212 | 216 | 217 | 221 | 222 | 223 | 224 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /Resources/config/helper/renderer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 14 | 15 | 16 | 17 | 23 | 24 | 25 | 26 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | 48 | 49 | 54 | 55 | 60 | 61 | 66 | 67 | 71 | 72 | 77 | 78 | 83 | 84 | 85 | 86 | 91 | 92 | 93 | 94 | 95 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 111 | 112 | 117 | 118 | 119 | 120 | 121 | 126 | 127 | 128 | 129 | 130 | 131 | 136 | 137 | 142 | 143 | 144 | 145 | 146 | 151 | 152 | 153 | 154 | 155 | 156 | 161 | 162 | 167 | 168 | 173 | 174 | 179 | 180 | 185 | 186 | 191 | 192 | 197 | 198 | 203 | 204 | 205 | 206 | 211 | 212 | 217 | 218 | 219 | 220 | 221 | 226 | 227 | 232 | 233 | 238 | 239 | 244 | 245 | 250 | 251 | 252 | 253 | 254 | 255 | 260 | 261 | 266 | 267 | 272 | 273 | 278 | 279 | 280 | 281 | 282 | 287 | 288 | 293 | 294 | 299 | 300 | 305 | 306 | 307 | 308 | 312 | 313 | 318 | 319 | 320 | 321 | 326 | 327 | 328 | 329 | 334 | 335 | 336 | 337 | 338 | 339 | 344 | 345 | 346 | 347 | 348 | 353 | 354 | 355 | 356 | 357 | 358 | 363 | 364 | 369 | 370 | 375 | 376 | 381 | 382 | 383 | 384 | 389 | 390 | 395 | 396 | 401 | 402 | 407 | 408 | 409 | 410 | 415 | 416 | 417 | 418 | 423 | 424 | 429 | 430 | 435 | 436 | 441 | 442 | 447 | 448 | 449 | 450 | 455 | 456 | 461 | 462 | 463 | 464 | 469 | 470 | 471 | 472 | 477 | 478 | 479 | 480 | 484 | 485 | 489 | 490 | 494 | 495 | 496 | 497 | 498 | 502 | 503 | 507 | 508 | 512 | 513 | 514 | 515 | 516 | 517 | 521 | 522 | 523 | 524 | 525 | 529 | 530 | 531 | 532 | 536 | 537 | 538 | 539 | 543 | 544 | 545 | 546 | 547 | 551 | 552 | 556 | 557 | 558 | 559 | 563 | 564 | 569 | 570 | 575 | 576 | 581 | 582 | 587 | 588 | 593 | 594 | 595 | -------------------------------------------------------------------------------- /Resources/config/helper/subscriber.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 14 | 15 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 52 | 53 | 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | 70 | 71 | 72 | 73 | 74 | 75 | 80 | 81 | 82 | 83 | 88 | 89 | 90 | 91 | 92 | 93 | 98 | 99 | 100 | 101 | 106 | 107 | 108 | 109 | 110 | 111 | 116 | 117 | 118 | 119 | 120 | 121 | 126 | 127 | 128 | 129 | 130 | 131 | 136 | 137 | 138 | 139 | 140 | 141 | 146 | 147 | 148 | 149 | 154 | 155 | 156 | 157 | 158 | 159 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 175 | 176 | 177 | 178 | 179 | 180 | 185 | 186 | 187 | 188 | 189 | 194 | 195 | 196 | 197 | 198 | 203 | 204 | 205 | 206 | 207 | 212 | 213 | 214 | 215 | 216 | 221 | 222 | 223 | 224 | 225 | 230 | 231 | 232 | 233 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 250 | 251 | 252 | 253 | 254 | 259 | 260 | 261 | 262 | 267 | 268 | 269 | 270 | 271 | 272 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 288 | 289 | 290 | 291 | 292 | 293 | 298 | 299 | 300 | 301 | 302 | 303 | 308 | 309 | 310 | 311 | 312 | 313 | 318 | 319 | 320 | 321 | 322 | 323 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 339 | 340 | 341 | 342 | 343 | 344 | 349 | 350 | 351 | 352 | 353 | 354 | 359 | 360 | 361 | 362 | 363 | 364 | 369 | 370 | 371 | 372 | 373 | 374 | 379 | 380 | 381 | 382 | 383 | 384 | 389 | 390 | 391 | 392 | 393 | 394 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 410 | 411 | 412 | 413 | 414 | 415 | 420 | 421 | 422 | 423 | 424 | 425 | 430 | 431 | 432 | 433 | 434 | 435 | 440 | 441 | 442 | 443 | 444 | 445 | 450 | 451 | 452 | 453 | 454 | 459 | 460 | 461 | 462 | 463 | 468 | 469 | 470 | 471 | 472 | 477 | 478 | 479 | 480 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 497 | 498 | 499 | 500 | 505 | 506 | 507 | 508 | 509 | 510 | 515 | 516 | 517 | 518 | 519 | 520 | 525 | 526 | 527 | 528 | 533 | 534 | 535 | 536 | 537 | 538 | 543 | 544 | 545 | 546 | 547 | 548 | 553 | 554 | 555 | 556 | 557 | 558 | 563 | 564 | 565 | 566 | 567 | 568 | 572 | 573 | 574 | 575 | 579 | 580 | 581 | 582 | 583 | 587 | 588 | 589 | 590 | 591 | 592 | 596 | 597 | 598 | 599 | 600 | 601 | 605 | 606 | 607 | 608 | 612 | 613 | 614 | 615 | 619 | 620 | 621 | 622 | 623 | 624 | 628 | 629 | 630 | 631 | 632 | 633 | 637 | 638 | 639 | 640 | 644 | 645 | 646 | 647 | 648 | 652 | 653 | 654 | 655 | 659 | 660 | 661 | 662 | 667 | 668 | 669 | 670 | 671 | 672 | --------------------------------------------------------------------------------