baspa / zip-code-location-lookup
y
Fund package maintenance!
baspa
Requires
- php: ^8.1||^8.2
- illuminate/contracts: ^9.0||^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
This package allows you to lookup the geographic location of a zip code by combining the Postcode.tech API with the Google Geocoding API.
Installation
You can install the package via composer:
composer require baspa/zip-code-location-lookup
Then add the Google Maps API and Postcode.tech API keys to your .env
file:
GOOGLE_MAPS_API_KEY=your_api_key
POSTCODE_TECH_API_KEY=your_api_key
Then add those keys to the services.php
config file:
return [ // ... 'google' => [ 'api_key' => env('GOOGLE_MAPS_API_KEY'), ], 'postcode_tech' => [ 'api_key' => env('POSTCODE_TECH_API_KEY'), ], ];
Usage
use Baspa\ZipCodeLocationLookup\ZipCodeLocationLookup; // With Google Maps integration (default) $lookup = new ZipCodeLocationLookup(); // Without Google Maps integration $lookup = new ZipCodeLocationLookup(false); // Lookup a zip code $result = $lookup->lookup(zipCode: '1011AB', number: 1); // Returns an array containing: // - postcode: The normalized postcode // - street: Street name // - city: City name // - municipality: Municipality name // - province: Province name // - lat: Latitude coordinate // - lng: Longitude coordinate $result = [ 'postcode' => '1011 AB', 'street' => 'Dam', 'city' => 'Amsterdam', 'municipality' => 'Amsterdam', 'province' => 'Noord-Holland', 'lat' => 52.373169, 'lng' => 4.893379 ];
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.