teamzac / geocoder
A simple wrapper about Google's geocoding and direction services
Installs: 102
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 4
Type:project
Requires
- php: >=7.2.5
- guzzlehttp/guzzle: ^6.0|^7.0.1
- illuminate/console: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- orchestra/testbench: 5.*|6.*
- phpunit/phpunit: ^8.5|^9.0
This package is auto-updated.
Last update: 2025-03-05 22:09:56 UTC
README
Installation
You can install the package via composer:
composer require teamzac/geocoder
Usage
This package uses Laravel's autodiscovery feature, so you do not have to manually add the service provider.
You can publish the config file if you'd like, or simply add the following to your .env file:
GOOGLE_MAPS_API_KEY={{YOUR API KEY HERE}}
The TeamZac\Geocoder\Geocoder
class can be resolved from the container, or you can use the facade. There are two primary methods on this class:
// get lat/lng from an address Geocoder::geocode('1600 Pennsvylvania Ave, Washington DC 20500'); // get an address from lat/lng pair Geocoder::reverseGeocode(38.8976633, -77.036573);
Both methods will return an instance of TeamZac\Geocoder\GeocodeResult
, or throw an exception if no results were found.
The GeocodeResult
class is a simple data transfer object that makes it more convenience to access information about the response.
$result = Geocoder::geocode('123 main street anywhere USA'); $result->getState(); $result->getLocality(); $result->getStreetNumber();
For a full list of available methods, just check out the class' implementation.
Testing
composer test
You'll want to copy the .env.example
file as .env.testing.php
and add your Google Maps API key to enable testing.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email chad@zactax.com instead of using the issue tracker.