yaroslawww / laravel-geonames
在项目中导入并操作地理名称数据。
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-09-12 19:03:26 UTC
README
在项目中导入并操作地理名称数据。
安装
通过composer安装包
composer require yaroslawww/laravel-geonames
# or
composer require yaroslawww/laravel-geonames --dev
可选地,您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="LaraGeoData\ServiceProvider" --tag="config"
允许导入本地文件
[
'mysql_geo' => [
// ....
'options' => [PDO::MYSQL_ATTR_LOCAL_INFILE=>true],
],
]
使用方法
命令
操作dump文件
下载dump文件
php artisan geonames:download GB.zip FR.zip --postal=GB.zip --postal=GB_full.csv.zip --postal=FR.zip --extract --force
清除所有下载的文件
php artisan geonames:download:truncate
创建迁移
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
将dump数据导入到表中
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
模型
地理编码
初始化表
$model = new Geoname();
# or
$model = Geoname::makeUsingSuffix('gb');
# or
# .env: GEONAMES_DEFAULT_SUFFIX=gb
$model = new Geoname();
使用表
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;