This package allows you to use Geocoder in Laravel 4.
It can be found on Packagist. The recommended way is through composer.
Edit composer.json
and add:
{
"require": {
"toin0u/geocoder-laravel": "@stable"
}
}
Protip: you should browse the
toin0u/geocoder-laravel
page to choose a stable version to use, avoid the @stable
meta constraint.
And install dependencies:
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
Find the providers
key in app/config/app.php
and register the Geocoder Service Provider.
'providers' => array(
// ...
'Toin0u\Geocoder\GeocoderServiceProvider',
)
Find the aliases
key in app/config/app.php
and register the Geocoder Facade.
'aliases' => array(
// ...
'Geocoder' => 'Toin0u\Geocoder\GeocoderFacade',
)
Publish and edit the configuration file
$ php artisan config:publish toin0u/geocoder-laravel
The service provider creates the following services:
geocoder
: the Geocoder instance.geocoder.chain
: the chain provider used by Geocoder.geocoder.adapter
: the HTTP adapter used to get data from remotes APIs.
By default, the geocoder.chain
service contains GoogleMapsProvider
and FreeGeoIpProvider
.
The geocoder.adapter
service uses the cURL adapter. Override these services to use the
adapter/providers you want by editing app/config/packages/toin0u/geocoder-laravel/config.php
:
return array(
'providers' => array(
'Geocoder\Provider\GoogleMapsProvider' => array('my-locale', 'my-region', $ssl = true, 'my-api-key'),
'Geocoder\Provider\GoogleMapsBusinessProvider' => array(
'my-client-id', 'my-api-key', 'my-locale', 'my-region', $ssl = true
),
'Geocoder\Provider\CloudMadeProvider' => array('my-api-key'),
'Geocoder\Provider\FreeGeoIpProvider' => null, // or array()
// ...
),
'adapter' => 'Geocoder\HttpAdapter\CurlHttpAdapter'
);
NB: As you can see the array value of the provider is the constructor arguments.
See the Geocoder documentation for a list of available adapters and providers.
<?php
// ...
try {
$geocode = Geocoder::geocode('10 rue Gambetta, Paris, France');
// The GoogleMapsProvider will return a result
var_dump($geocode);
} catch (\Exception $e) {
// No exception will be thrown here
echo $e->getMessage();
}
Please open an issue on GitHub
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
This Code of Conduct is adapted from the Contributor Covenant, version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/
GeocoderLaravel is released under the MIT License. See the bundled LICENSE file for details.