geocoder-php/geonames-provider
GeoNames provider for the PHP Geocoder library. Adds forward/reverse geocoding and place lookup via the GeoNames API, with configurable options and integration alongside other Geocoder providers for consistent address and location results.
geonames-provider package extends the geocoder-php library, enabling reverse geocoding (coordinates → location) and forward geocoding (address → coordinates) via the GeoNames API. This is a niche but critical feature for:
Illuminate\Support\Facades\Cache and Http clients can seamlessly integrate with this provider, reducing boilerplate. The package’s adherence to the Geocoder PHP interface ensures compatibility with Laravel’s service container and dependency injection.http://api.geonames.org/findNearbyPlaceNameJSON). Laravel’s Http client can handle this with minimal overhead..env can store this securely.Location table with latitude, longitude, country_code).Http client or Mockery, but real API calls may need stubbing for CI/CD.| Risk Area | Mitigation Strategy |
|---|---|
| API Rate Limits | Implement Laravel’s throttle middleware or a custom decorator to cache responses. |
| Deprecation | GeoNames API changes may break the provider. Monitor GeoNames’ changelog. |
| Data Accuracy | Validate against OpenStreetMap or Google Maps for critical use cases. |
| Performance | GeoNames’ free tier has latency (~200ms–500ms). Cache aggressively (e.g., Redis). |
| Dependency Bloat | The package is minimal, but geocoder-php adds ~1MB to vendor size. |
AppServiceProvider:
use Geocoder\Geocoder;
use Geocoder\Provider\GeoNamesProvider;
public function register()
{
$geocoder = new Geocoder();
$geocoder->registerProvider(new GeoNamesProvider(config('services.geonames.username')));
$this->app->singleton('geocoder', fn() => $geocoder);
}
Geocoder facade for clean syntax:
use Illuminate\Support\Facades\Facade;
class GeocoderFacade extends Facade { protected static function getFacadeAccessor() { return 'geocoder'; } }
$coordinates = Geocoder::forwardGeocodeQuery('1600 Amphitheatre Parkway, Mountain View')->get();
$location = Geocoder::reverseGeocodeQuery(37.422, -122.084)->get();
locations table with fields like geoname_id, name, country_code, admin_code1 (state/province).Http client mocking and real API calls.AppServiceProvider.json and mbstring are assumed.geocoder-php/geocoder and geocoder-php/geonames-provider to composer.json..env:
GEONAMES_USERNAME=your_username_here
Http client).geocoder-php and geonames-provider for updates (low maintenance burden).Http client if the package drops PHP 8.1 support.Log::debug($response->getBody())).Http client middleware to inspect requests/responses.geocoder-php’s GitHub issues or GeoNames’ forums.adminCode1 → Laravel’s state field).| Scenario | Impact | Mitigation |
|---|---|---|
| GeoNames API Down | Geocoding fails for users. | Fallback to OpenStreetMap or local DB cache. |
| Rate Limit Exceeded | 429 errors; degraded performance. | Implement exponential backoff and caching. |
| Data Inconsistency | Incorrect place names/coordinates. | Cross-validate with Google Maps or OSM. |
| Dependency Update | Breaking changes in geocoder-php. |
Pin versions in composer.json until stable. |
How can I help you explore Laravel packages today?