roundly-consulting / geolocation-for-laravel
Resolve a client's location and travel distance through pluggable geolocation providers for Laravel.
Package info
github.com/roundly-consulting/geolocation-for-laravel
pkg:composer/roundly-consulting/geolocation-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- ext-phar: *
- ext-zlib: *
- illuminate/contracts: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/http-client-rate-limits-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Geolocation for Laravel
Resolve a client's location from an IP address, coordinates or a street address, and the travel
distance between two points, through a pluggable pipeline of providers: IPinfo, IP2Location,
Google, MaxMind (with a native .mmdb reader) and a configurable fallback.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/geolocation-for-laravel
IP lookups work out of the box through IP2Location and IPinfo. Address lookups and distances go
through Google and need GOOGLE_MAPS_API_KEY in your .env.
Usage
Locate the visitor, geocode an address and measure a drive, all through the facade:
use RoundlyConsulting\Geolocation\DataTransferObjects\Coordinates; use RoundlyConsulting\Geolocation\Enum\DistanceType; use RoundlyConsulting\Geolocation\Facades\Geolocation; $location = Geolocation::locateRequest(); // the client's IP; null when nothing resolves $location?->city; // "Mountain View" $location?->countryIsoCode; // "US" $location?->timezone; // "America/Los_Angeles" $office = Geolocation::locateAddress('1600 Amphitheatre Pkwy, Mountain View'); $office?->coordinates(); // Coordinates(37.4224, -122.0841) $distance = Geolocation::distanceBetween( new Coordinates(48.1482, 17.1067), new Coordinates(49.2000, 16.6068), DistanceType::Driving, ); $distance?->humanReadableDistance; // "133 km" $distance?->durationInSeconds; // 5400
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/geolocation-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md.