thomsult/laravel-mapbox
Composer 安装命令:
composer require thomsult/laravel-mapbox
包简介
Laravel package pour les appels API Mapbox (geocoding, directions, etc.)
README 文档
README
Un package Laravel élégant et typé pour intégrer les APIs Mapbox (geocoding, search, directions) dans vos applications Laravel.
✨ Fonctionnalités
- 🎯 API typée - Auto-complétion complète et type safety
- 🚀 Fluent API - Interface intuitive
- 🔧 Configuration simple - Prêt à l'emploi en quelques minutes
- 📍 Support complet - Search Box API, Geocoding API
- ⚡ Laravel intégré - Service Provider, Facade, Configuration, Cache, Rate Limiting, Lock
- 🧪 Testé - Tests unitaires et d'intégration
📋 Prérequis
- PHP 8.1+
- Laravel 12.0+
- Token d'accès Mapbox
🚀 Installation
Installez le package via Composer :
composer require thomsult/laravel-mapbox
Publiez le fichier de configuration :
php artisan vendor:publish --provider="Thomsult\LaravelMapbox\Providers\MapboxServiceProvider" --tag="config"
Ajoutez votre token Mapbox dans votre fichier .env :
MAPBOX_ACCESS_TOKEN=votre_token_mapbox_ici
🔧 Configuration
Le fichier de configuration config/mapbox.php permet de personnaliser :
return [ 'access_token' => env('MAPBOX_ACCESS_TOKEN'), 'base_uri' => 'https://api.mapbox.com/', 'debug' => env('MAPBOX_DEBUG', false), 'cache' => [ 'enabled' => env('MAPBOX_CACHE_ENABLED', true), 'duration' => env('MAPBOX_CACHE_DURATION', 15), 'timeout' => env('MAPBOX_CACHE_TIMEOUT', 5) ], 'rate' => [ 'enabled' => env('MAPBOX_RATE_ENABLED', true), 'limit' => env('MAPBOX_RATE_LIMIT', 60), 'decay' => env('MAPBOX_RATE_DECAY', 60), ], 'search' => [ 'api_version' => 'v1/', 'prefix' => 'search/', 'base_endpoint' => 'searchbox/', 'forward_endpoint' => 'forward', 'suggest_endpoint' => 'suggest', 'retrieve_endpoint' => 'retrieve', 'category_endpoint' => 'category', 'category_list_endpoint' => 'list/category', 'reverse_endpoint' => 'reverse', ], 'geocoding' => [ 'api_version' => 'v6/', 'prefix' => 'search/', 'base_endpoint' => 'geocode/', 'forward_endpoint' => 'forward', 'reverse_endpoint' => 'reverse', 'batch_endpoint' => 'batch' ] ];
📖 Utilisation
Recherche de base
Artisan::command('mapbox:search {query}', function ($query) { $this->comment('Mapbox search command'); $response = MapboxClient::client() ->autocomplete(fn($req) => $req ->query($query) ->options(fn($options) => $options ->types([PlaceType::PLACE->value]) ->limit(2) ->country('FR') ->language('fr'))) ->call(); }); dd($response); // Affiche la réponse de l'API
Recherche inversée
Artisan::command('mapbox:search:reverse {longitude} {latitude}', function (string $longitude, string $latitude) { $this->comment('Mapbox search command'); $response = MapboxClient::client()->reverse( fn($req) => $req ->longitude($longitude) ->latitude($latitude) ->options( fn($options) => $options ->language('fr') ) ) ->call(); dd($response); });
Recherche Groupée
Artisan::command('mapbox:geocoding:batch', function () { $this->comment('Mapbox search command'); $response = MapboxClient::client()->batch( fn($req) => $req ->body( fn($body) => $body ->add( (new ForwardTextRequest()) ->query("1600 Pennsylvania Avenue NW, Washington, DC 20500, United States") ->options( fn($options) => $options ->types("address") ->bbox("-80, 35, -70, 40") ->limit(1) ) ) ->add( (new ForwardTextRequest()) ->query("1605 Pennsylvania Avenue NW, Washington, DC 20500, United States") ->options( fn($options) => $options ->types("address") ->bbox("-80, 35, -70, 40") ->limit(1) ) ) ) ) ->call(); });
Types de lieux disponibles
use Thomsult\LaravelMapbox\Enums\PlaceType; case COUNTRY = 'country'; case REGION = 'region'; case POSTCODE = 'postcode'; case DISTRICT = 'district'; case PLACE = 'place'; case CITY = 'city'; case LOCALITY = 'locality'; case NEIGHBORHOOD = 'neighborhood'; case STREET = 'street'; case ADDRESS = 'address'; case POI = 'poi'; case CATEGORY = 'category'; case UNKNOWN = 'unknown';
Utilisation dans des commandes Artisan
Artisan::command('mapbox:search {query}', function ($query) { $this->comment('Mapbox search command'); $response = MapboxClient::client() ->autocomplete(fn($req) => $req ->query($query) ->options(fn($options) => $options ->types([PlaceType::PLACE->value]) ->limit(2) ->country('FR') ->language('fr'))) ->call(); });
🧪 Tests
Tests unitaires
composer test
🤝 Contribution
Les contributions sont les bienvenues ! Merci de :
- Fork le projet
- Créer une branche pour votre fonctionnalité
- Commiter vos changements
- Pousser vers la branche
- Créer une Pull Request
📄 Licence
Ce package est sous licence MIT. Voir le fichier LICENSE pour plus de détails.
🙏 Remerciements
📞 Support
Créé avec ❤️ par Sultan Thomas
thomsult/laravel-mapbox 适用场景与选型建议
thomsult/laravel-mapbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「api」 「search」 「maps」 「laravel」 「directions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thomsult/laravel-mapbox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thomsult/laravel-mapbox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thomsult/laravel-mapbox 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
A Laravel package to retrieve data from Google Search Console
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Abstraction Layer to index and search entities
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-06