yaroslawww / laravel-geonames
Import and manipulate geonames data in your project.
2.0.1
2022-09-12 14:58 UTC
Requires
- php: ^8.1
- ext-zip: *
- illuminate/support: ^9.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- orchestra/testbench: ^7.7
- phpunit/phpunit: ^9.5
- psalm/plugin-laravel: ^2.0
- vimeo/psalm: ^4.27
This package is auto-updated.
Last update: 2024-11-12 19:23:25 UTC
README
Import and manipulate geonames data in your project.
Installation
Install the package via composer:
composer require yaroslawww/laravel-geonames
# or
composer require yaroslawww/laravel-geonames --dev
Optionally you can publish the config file with:
php artisan vendor:publish --provider="LaraGeoData\ServiceProvider" --tag="config"
Allow import local infile:
[
'mysql_geo' => [
// ....
'options' => [PDO::MYSQL_ATTR_LOCAL_INFILE=>true],
],
]
Usage
Commands
Manipulate dump files
Download dump files:
php artisan geonames:download GB.zip FR.zip --postal=GB.zip --postal=GB_full.csv.zip --postal=FR.zip --extract --force
Clear all downloaded files:
php artisan geonames:download:truncate
Make migrations
php artisan geonames:make:migration geonames
# or
php artisan geonames:make:migration geonames --suffix=gb
php artisan geonames:make:migration postalcodes --suffix=gb
php artisan geonames:make:migration admin_areas_view --suffix=gb --replaces=level:1
php artisan geonames:make:migration admin_areas_view --suffix=gb --replaces=level:2
php artisan geonames:make:migration admin_areas_view --suffix=gb --replaces=level:3
Import dump data to tables
php artisan geonames:import:file-to-db geonames # or php artisan geonames:import:file-to-db geonames --suffix=gb # or php artisan geonames:import:file-to-db geonames path/to/my/file.csv --suffix=gb php artisan geonames:import:file-to-db postalcodes --suffix=gb php artisan geonames:import:file-to-db postalcodes postal_codes/GB_full.txt --suffix=gb
Models
Geocodes
Initialise table:
$model = new Geoname();
# or
$model = Geoname::makeUsingSuffix('gb');
# or
# .env: GEONAMES_DEFAULT_SUFFIX=gb
$model = new Geoname();
Use table:
Geoname::nearestInMiles(24.76778, 56.16306, 1.5)->orderByNearest()->get()
// or
$model = Geoname::makeUsingSuffix('gb');
$nearestLocation = $model->newQuery()->nearestInMiles(24.76778, 56.16306, 1.5)->orderByNearest()->firstOrFail();
echo $nearestLocation->distance;