定制 kulykovoleksii/laravel-geocoding 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kulykovoleksii/laravel-geocoding

Composer 安装命令:

composer require kulykovoleksii/laravel-geocoding

包简介

Universal geocoding and postal code lookup for PHP with support for multiple countries. Framework-agnostic core with first-class Laravel integration.

README 文档

README

Universal geocoding and postal code lookup package for Laravel with support for multiple countries worldwide.

Features

  • Multi-country support (UK, USA, Ukraine, Canada, and more)
  • Multiple geocoding providers with automatic fallback
  • Free UK postcode lookup via Postcodes.io API
  • Google Maps Geocoding API integration for worldwide coverage
  • Database caching to minimize API calls
  • Reverse geocoding from coordinates to addresses
  • Hierarchical region management
  • Comprehensive test suite

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0 or 11.0
  • MySQL/PostgreSQL database

Installation

Install the package via Composer:

composer require kulykovoleksii/laravel-geocoding

Publish the configuration file:

php artisan vendor:publish --tag=geocoding-config

Publish and run migrations:

php artisan vendor:publish --tag=geocoding-migrations
php artisan migrate

Configuration

Add your Google Maps API key to .env (optional but recommended for worldwide coverage):

GOOGLE_MAPS_API_KEY=your_api_key_here

Get your API key at: https://console.cloud.google.com/google/maps-apis

Pricing: $200/month free credit (approximately 40,000 requests/month free)

Usage

Basic Usage

use Kulykovoleksii\Geocoding\Services\Geocoding\GeocodingService;

$geocoding = app(GeocodingService::class);

// Lookup UK postcode (uses free Postcodes.io)
$result = $geocoding->lookupPostalCode('SW1A 1AA');

echo $result->getFullAddress(); // Westminster, London, SW1A 1AA
echo $result->latitude;  // 51.5033
echo $result->longitude; // -0.1276

Lookup Different Countries

// USA ZIP code
$result = $geocoding->lookupPostalCode('90210');
echo $result->city;  // Beverly Hills
echo $result->state; // California

// Ukraine postal code
$result = $geocoding->lookupPostalCode('01001');
echo $result->city; // Kyiv

Geocode Full Address

$result = $geocoding->geocode('10 Downing Street, London, UK');

echo $result->latitude;   // 51.5033
echo $result->longitude;  // -0.1276
echo $result->postalCode; // SW1A 2AA

Reverse Geocoding

$result = $geocoding->reverseGeocode(51.5033, -0.1276);

echo $result->getFullAddress();
// Output: 10 Downing Street, Westminster, London, SW1A 2AA

Using Facade

use Kulykovoleksii\Geocoding\Facades\Geocoding;

$result = Geocoding::lookupPostalCode('SW1A 1AA');

Working with Regions

use Kulykovoleksii\Geocoding\Models\Region;
use Kulykovoleksii\Geocoding\Models\PostalCode;

// Create region hierarchy
$uk = Region::create([
    'name' => 'United Kingdom',
    'slug' => 'uk',
    'country_code' => 'GB',
    'type' => 'country',
]);

$london = Region::create([
    'name' => 'London',
    'slug' => 'london',
    'country_code' => 'GB',
    'type' => 'city',
    'parent_id' => $uk->id,
]);

// Query regions
$ukRegions = Region::byCountry('GB')->get();
$cities = Region::byType('city')->get();
$countries = Region::roots()->get();

Supported Postal Code Formats

Country Code Format Example Provider
United Kingdom GB SW1A 1AA, M1 1AA Postcodes.io
United States US 90210, 10001-1234 Google Maps
Ukraine UA 01001, 79000 Google Maps
Canada CA K1A 0B1 Google Maps
Others * Various Google Maps

Geocoding Providers

Postcodes.io (UK only, free)

Automatically used for UK postcodes. No configuration required.

Google Maps Geocoding API (Universal)

Used for non-UK addresses or when Postcodes.io doesn't have data. Requires API key in configuration.

Caching Strategy

All geocoding results are automatically cached in the database:

  1. First lookup checks the database cache
  2. If not found, queries the appropriate geocoding provider
  3. Results are stored in the postal_codes table
  4. Subsequent lookups use cached data
  5. Reverse geocoding uses proximity search for nearby cached coordinates

This minimizes API calls and costs, especially for paid services like Google Maps.

Testing

Run the test suite:

composer test

Or using PHPUnit directly:

vendor/bin/phpunit

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Security

If you discover any security-related issues, please email oleksii.eng@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

kulykovoleksii/laravel-geocoding 适用场景与选型建议

kulykovoleksii/laravel-geocoding 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「geocoding」 「address」 「google-maps」 「geolocation」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kulykovoleksii/laravel-geocoding 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kulykovoleksii/laravel-geocoding 我们能提供哪些服务?
定制开发 / 二次开发

基于 kulykovoleksii/laravel-geocoding 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-08