topukhan/geokit
Composer 安装命令:
composer require topukhan/geokit
包简介
A clean and extensible geocoding toolkit for Laravel
README 文档
README
A clean and extensible geocoding toolkit for Laravel that supports multiple providers with automatic fallback handling.
Features
- 🌍 Multiple Providers: Geoapify (premium) and Nominatim (free) support
- 🔄 Smart Fallback: Automatically falls back to next provider if one fails
- 🛡️ Quota Protection: Detects API quota issues and handles them gracefully
- 🎯 Consistent Results: Unified response format across all providers
- ⚡ Laravel Integration: Facade and Service injection support
- 🔧 Configurable: Easy configuration and extensible architecture
Installation
Install the package via Composer:
composer require topukhan/geokit
Publish the configuration file:
php artisan vendor:publish --tag=geokit-config
Configuration
Environment Variables
Add these variables to your .env file:
# Optional: Your Geoapify API key (if you have one) GEOKIT_GEOAPIFY_KEY=your_geoapify_api_key_here # Optional: Request timeout in seconds (default: 30) GEOKIT_TIMEOUT=30 # Optional: Maximum results per search (default: 10) GEOKIT_MAX_RESULTS=10 # Optional: User agent for API requests GEOKIT_USER_AGENT="Your App Name/1.0"
Config File
The config/geokit.php file allows you to customize:
- Provider order and selection
- API keys
- Request timeouts
- Result limits
Usage
Using the Facade
use Topukhan\Geokit\Facades\Geokit; $response = Geokit::search('Tongi, Dhaka'); // Check if we got results if ($response->hasResults()) { echo "Found {$response->count()} results\n"; // Get the first result $first = $response->first(); echo "Best match: {$first->formatted}\n"; echo "Coordinates: {$first->lat}, {$first->lng}\n"; echo "Provider: {$first->provider}\n"; // Access address components if (isset($first->components['city'])) { echo "City: {$first->components['city']}\n"; } } // Check if fallback was used if ($response->usedFallback) { echo "Used fallback providers\n"; } // See which providers failed if (!empty($response->failedProviders)) { echo "Failed providers: " . implode(', ', $response->failedProviders) . "\n"; }
Using Service Injection
use Topukhan\Geokit\Services\AddressResolverService; class LocationController extends Controller { public function search(Request $request, AddressResolverService $geokit) { $response = $geokit->search($request->input('query')); return response()->json($response->toArray()); } }
Response Format
All searches return a GeocodeResponse object with this structure:
GeocodeResponse {
+query: string // Original search query
+results: array // Array of GeocodeResult objects
+usedFallback: bool // Whether fallback providers were used
+failedProviders: array // Names of providers that failed
}
Each result in the results array is a GeocodeResult object:
GeocodeResult {
+provider: string // Provider name (e.g., 'geoapify', 'nominatim')
+formatted: string // Full formatted address
+lat: float // Latitude
+lng: float // Longitude
+components: array // Address components (city, state, country, etc.)
}
Example Response
{
"query": "Tongi, Dhaka",
"results": [
{
"provider": "geoapify",
"formatted": "Tongi, Gazipur District, Dhaka Division, Bangladesh",
"lat": 23.8896,
"lng": 90.3961,
"components": {
"city": "Tongi",
"district": "Gazipur District",
"state": "Dhaka Division",
"country": "Bangladesh",
"country_code": "BD"
}
}
],
"usedFallback": false,
"failedProviders": []
}
Provider Details
Geoapify
- Type: Premium (requires API key)
- Quota: Varies by plan
- Accuracy: High
- Coverage: Global
Nominatim
- Type: Free (no API key required)
- Quota: Rate limited
- Accuracy: Good
- Coverage: Global (OpenStreetMap data)
Error Handling
The package handles various error scenarios automatically:
- Invalid API Keys: Automatically falls back to next provider
- Quota Exceeded: Detects quota issues and skips provider
- Network Timeouts: Respects configured timeout limits
- Rate Limits: Handles rate limiting gracefully
Extending with New Providers
To add a new geocoding provider:
- Create a new class implementing
GeocodingDriverInterface - Add it to the service provider's provider mapping
- Update the configuration file
Example:
use Topukhan\Geokit\Contracts\GeocodingDriverInterface; class GoogleGeocoder implements GeocodingDriverInterface { public function getName(): string { return 'google'; } // Implement other interface methods... }
Requirements
- PHP 8.2+
- Laravel 10.0+
License
This package is open-sourced software licensed under the MIT license.
topukhan/geokit 适用场景与选型建议
topukhan/geokit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「nominatim」 「laravel」 「location」 「address-search」 「geoapify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 topukhan/geokit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 topukhan/geokit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 topukhan/geokit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Integrates an OpenStreetMap tile proxy in TYPO3 for GDPR-compliant integration.
Nominatim Geocoding API Client
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-12