Laravel package to convert any address to GPS coordinates.
Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
You can install this package through composer.
composer require spatie/geocoder
Note: use ^1.0 for Laravel 4 support
When using Laravel there is a service provider that you can make use of.
// config/app.php
'providers' => [
'...',
'Spatie\Geocoder\GeocoderServiceProvider'
];
Geocoder also comes with a facade, which provides an easy way to call the Geocoder.
// config/app.php
'aliases' => array(
...
'Geocoder' => 'Spatie\Geocoder\GeocoderFacade',
)
Geocoder::getCoordinatesForQuery('Infinite Loop 1, Cupertino');
/*
This function returns an array with keys
"lat" => 37.331741000000001
"lng" => -122.0303329
"accuracy" => "ROOFTOP"
*/
The accuracy key can contain these values:
- 'ROOFTOP'
- 'RANGE_INTERPOLATED'
- 'GEOMETRIC_CENTER'
- 'APPROXIMATE'
You can read more information about these values on the Google Geocoding API Page
When an address is not found accuracy will contain 'NOT_FOUND'
Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.