https://github.com/baspa/zip-code-location-lookup
Look up geolocation (Google) based on an address using Google and Postcode.tech
https://github.com/baspa/zip-code-location-lookup
geolocation google google-geocoding-api postcode-lookup-service
Last synced: about 1 year ago
JSON representation
Look up geolocation (Google) based on an address using Google and Postcode.tech
- Host: GitHub
- URL: https://github.com/baspa/zip-code-location-lookup
- Owner: Baspa
- License: mit
- Created: 2025-01-21T15:01:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-03T20:37:19.000Z (over 1 year ago)
- Last Synced: 2025-04-06T04:59:47.495Z (about 1 year ago)
- Topics: geolocation, google, google-geocoding-api, postcode-lookup-service
- Language: PHP
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Zip Code Location Lookup
[](https://packagist.org/packages/baspa/zip-code-location-lookup)
[](https://github.com/baspa/zip-code-location-lookup/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/baspa/zip-code-location-lookup/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/baspa/zip-code-location-lookup)
This package allows you to lookup the geographic location of a zip code by combining the [Postcode.tech](https://postcode.tech/) API with the [Google Geocoding API](https://developers.google.com/maps/documentation/geocoding/overview).
## Installation
You can install the package via composer:
```bash
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:
```php
return [
// ...
'google' => [
'api_key' => env('GOOGLE_MAPS_API_KEY'),
],
'postcode_tech' => [
'api_key' => env('POSTCODE_TECH_API_KEY'),
],
];
```
## Usage
```php
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
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Baspa](https://github.com/Baspa)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.