codeblog.pro / laravel-geo-location
The package allows you to get the location of the user by his IP. The package provides the ability to use several services at the same time to increase accuracy and to increase free limits.
Requires
- php: >=7.4
- codeblog.pro/geo-coordinates: ^1.0.0
- codeblog.pro/geo-location-address: ^0.0.1
- guzzlehttp/guzzle: ^7.0
- illuminate/routing: ^7.23
- illuminate/support: ^7.9
Requires (Dev)
- nunomaduro/phpinsights: ^1.14
- phpstan/phpstan: ^0.12.47
- phpunit/php-code-coverage: ^8.0
- phpunit/phpunit: ^9.0.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-10-30 01:26:33 UTC
README
The package is a wrapper for several geolocation services at once. The main task of the package is to determine the user's location by IP. Due to the possibility of using several providers at once, the free limit of each provider is summed up.
Install
Via Composer
$ composer require codeblog.pro/geo-location
Usage
// First way: in code $geoLocationService = new \CodeblogPro\GeoLocation\Application\Services\GeoLocationService(); $location = $geoLocationService->getLocationByIpAndLanguageResultCode('8.8.8.8', 'EN'); var_dump($location); $locationArray = $geoLocationService->getLocationArrayByIpAndLanguageResultCode('8.8.8.8', 'RU'); var_dump($locationArray); $currentIpResolver = new \CodeblogPro\GeoLocation\Application\Services\CurrentIpResolver(); $currentIp = $geoLocationService->getCurrentIpByIpResolver($currentIpResolver)->getValue(); var_dump($currentIp); $locationByIpResolverAndLanguageResultCode = $geoLocationService->getLocationByIpResolverAndLanguageResultCode( $currentIpResolver, 'RU' ); var_dump($locationByIpResolverAndLanguageResultCode); // Second way (only for Laravel): using a GET request, // for example by url http://<our-domain>/api/geo-location/46.174.50.30/en // Result: // { // "data":{ // "latitude":55.07944, // "longitude":38.77833, // "country_name":"Russia", // "country_code":"RU", // "region_name":"Moskovskaya Oblast'", // "region_code":"RU-MOS", // "street_name":"", // "postal_code":"1404xx", // "locality":"Kolomna" // } // }
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email panov@codeblog.pro instead of using the issue tracker.
Credits
License
The Apache License License. Please see License File for more information.