With this bundle you can easily calculate the geo position from a given address, city, place or country over the Google Geocode API with Contao 4.4.*
A Google API key is required. You can generate a API key under the following link: https://developers.google.com/maps/documentation/geocoding/get-api-key
This bundle is currently under development. You can use it at your own risk! A stable version will be available soon. Of course you can submit issues and feature requests on the repository issue section. Thx!
Run in your project folder the following Composer command to add the Geocoding Bundle to your project:
./composer require wr/geocoding-bundle
Add the Bundle to app/AppKernel.php
bundles array after all the Contao bundles:
public function registerBundles()
{
$bundles = [
.....
new Wr\GeocodingBundle\WrGeocodingBundle() //Add this line.
];
....
return $bundles;
}
Clear the cache and warmup the cache with the following two commands:
./bin/console cache:clear --no-warmup --env=prod
./bin/console cache:warmup --env=prod
Go to the install tool and update the database. Then login into the back end.
Without the awesome Contao Manager
Run in your project folder the following Composer command to add the geocoding Bundle to your project:
composer require wr/geocoding-bundle
Clear the cache and warmup the cache with the following two commands:
vendor/bin/contao-console cache:clear --no-warmup
vendor/bin/contao-console cache:warmup
Go to the install tool and update the database. Then login into the back end.
With the awesome Contao Manager
- Search in the Contao Manager search bar the bundle
wr/geocoding-bundle
and click on the install button. - Go to the install tool and update the database. Then login into the back end.
php: ^7.0
symfony/symfony: ^3.3
contao/core-bundle: ^4.4
You can use the class with the container as follow:
$container=\Contao\System::getContainer();
$Geocoder=container->get('wr.geocoding.geocoder');
$Geocoder->calculate($address,$country,$apiKey);
If the request was successful the geocoder object return the response object from the Google API otherwise it will return NULL.
Alternatively you can access the following properties.
$Geocoder->lat; //return the latitute
$Geocoder->lng; //return the longitute
$Geocoder->coords; // return the coordinate in seprated with a coma
$Geocoder->formattedAddress; // return the address formatted by the Google Geocoding API
$Geocoder->placeId; //return the Google Place ID
$Geocoder->types; //return the Google Geo Position type
$Geocoder->status; //return the Google API status
$Geocoder->geocoderResponse; //return the response object form the Google API
The geocoding bundle is published under the LGPLv3.
Unfortunately, at the moment there is no documentation available. But we will fix this as soon as there is a stable version.
For further information feel free and get in contact with us: [email protected]
If you like our work feel free to donate.
There are many ways to donate to the project. The following list contains some possibilities: