baspa / zip-code-location-lookup
y
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/contracts: ^13.0
- spatie/laravel-package-tools: ^1.93
Requires (Dev)
- larastan/larastan: ^3.15
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.9
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0 || ^5.0
- pestphp/pest-plugin-arch: ^4.0 || ^5.0
- pestphp/pest-plugin-laravel: ^4.1 || ^5.0
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.6
- phpstan/phpstan-deprecation-rules: ^2.0.5
- phpstan/phpstan-phpunit: ^2.1.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This package looks up the street, city and coordinates of a Dutch zip code and house number with the Google Geocoding API. When geocoding only finds the postcode area, it falls back to the Google Places API and reverse geocoding to find the street.
Requirements
- PHP 8.3 or higher
- Laravel 13
On Laravel 9 to 12 or PHP 8.1 and 8.2, use version 0.2 of this package:
composer require baspa/zip-code-location-lookup:^0.2
Installation
You can install the package via composer:
composer require baspa/zip-code-location-lookup
Then add your Google Maps API key to your .env file. The key needs the Geocoding API; with the Places API also enabled, lookups that only match a postcode area find the street more often.
GOOGLE_MAPS_API_KEY=your_api_key
And add it to the services.php config file:
return [ // ... 'google' => [ 'api_key' => env('GOOGLE_MAPS_API_KEY'), ], ];
Usage
use Baspa\ZipCodeLocationLookup\ZipCodeLocationLookup; $result = (new ZipCodeLocationLookup())->lookup(zipCode: '1012JS', number: 1); // [ // 'street' => 'Dam', // 'houseNumber' => 1, // 'postcode' => '1012JS', // 'city' => 'Amsterdam', // 'municipality' => 'Amsterdam', // 'province' => 'Noord-Holland', // 'country' => 'NLD', // 'lat' => 52.373169, // 'lng' => 4.893379, // ]
lookup() throws an InvalidArgumentException when the zip code can't be geocoded, and the constructor throws one when the Google Maps API key is missing.
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.