geocoder-php/pelias-provider
Pelias provider for PHP Geocoder. Connects to a Pelias-compatible geocoding API (self-hosted Pelias or services like Geocode Earth and OpenRouteService) to forward and reverse geocode addresses and coordinates.
Pros:
geocoder-php/Geocoder (≥5.0), ensuring compatibility with Laravel’s service container and dependency injection.Cons:
geocoder-php/Geocoder repo. Risk of stagnation if Pelias or PHP Geocoder evolves significantly.Laravel Stack Fit:
PeliasProvider to the container, enabling dependency injection.latitude/longitude columns).Dependencies:
geocoder-php/geocoder (≥5.0) and a PSR-18 HTTP client (e.g., guzzlehttp/guzzle or symfony/http-client). Laravel’s built-in HTTP client (v6+) satisfies this.$client = new \GuzzleHttp\Client(['base_uri' => 'https://your-pelias-instance.com']);
$provider = new \Geocoder\Provider\Pelias\PeliasProvider($client);
confidence, source) that require mapping to Laravel models?Laravel Ecosystem:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(\Geocoder\Provider\Pelias\PeliasProvider::class, function ($app) {
$client = new \GuzzleHttp\Client(['base_uri' => config('services.pelias.url')]);
return new \Geocoder\Provider\Pelias\PeliasProvider($client);
});
}
config/services.php:
'pelias' => [
'url' => env('PELIAS_URL', 'https://geocode.earth'),
'timeout' => 10,
'cache' => env('GEOCODER_CACHE', 'array'), // 'redis', 'database', etc.
],
$geocoder = new \Geocoder\Geocoder($provider);
$result = $geocoder->geocodeQuery('1600 Amphitheatre Parkway, Mountain View')->first();
Cache::remember("geocode_{$query}", now()->addHours(1), fn() => $result);
Database:
latitude/longitude (e.g., using spatie/laravel-geocoordinates for validation).Schema::table('addresses', function (Blueprint $table) {
$table->decimal('latitude', 10, 8)->nullable();
$table->decimal('longitude', 11, 8)->nullable();
$table->string('geocode_source')->nullable(); // e.g., 'pelias', 'geocode_earth'
});
config/caching.php to enable caching during testing.spatie/laravel-circuitbreaker) to fall back to a secondary provider (e.g., Nominatim) if Pelias fails.geocoder-php providers (e.g., Google Maps) via the Geocoder\Geocoder facade for multi-provider setups.How can I help you explore Laravel packages today?