Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Geonames Provider

Geonames Provider Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Geocoder Geonames adapter

Frequently asked questions about Geonames Provider
How do I install the GeoNames provider for Laravel using Composer?
Run `composer require geocoder-php/geocoder geocoder-php/geonames-provider` to install the package. The `geocoder-php/geocoder` library is a dependency, so it will be included automatically. Ensure your Laravel project meets PHP 8.0+ requirements.
What Laravel versions does this package support?
The package is framework-agnostic but works seamlessly with Laravel 8.x, 9.x, and 10.x. It leverages Laravel’s service container and HTTP client for integration, so no version-specific dependencies exist beyond PHP compatibility.
Do I need a paid GeoNames API plan, or is the free tier sufficient?
The free tier offers 2,000 requests per day, which may suffice for small projects or prototypes. For production apps with higher volume, upgrade to a paid plan (e.g., 10,000+ requests/day). Monitor usage via GeoNames’ dashboard to avoid throttling.
How can I cache GeoNames API responses in Laravel to improve performance?
Use Laravel’s built-in cache (e.g., Redis or file cache) by wrapping the Geocoder instance. For example, cache the entire geocoder client or individual responses with a TTL (e.g., 1 hour). The package itself doesn’t enforce caching, so implement it at the application level.
Can I use this provider alongside other Geocoder providers like OpenStreetMap?
Yes, the package follows the Geocoder PHP interface, allowing you to register multiple providers (e.g., GeoNames and Nominatim) and switch between them. Configure a fallback provider in your `AppServiceProvider` for redundancy if GeoNames fails.
How do I handle API rate limits or failures in production?
Implement Laravel’s `throttle` middleware or a custom decorator to cache responses and avoid hitting rate limits. For failures, use the Geocoder’s `fallback` method to chain providers or return cached data. Log errors to track outages and set up alerts for API downtime.
What data fields does GeoNames return, and how do I map them to a Laravel Eloquent model?
GeoNames returns structured data like `geonameId`, `name`, `countryCode`, `adminCode1` (state/province), `latitude`, `longitude`, and `timezone`. Map these to an Eloquent model (e.g., `Location`) with fillable fields. Use Laravel’s `casts` to convert strings to arrays or objects if needed.
Is this package suitable for GDPR-compliant location data handling?
GeoNames’ data is public and doesn’t inherently violate GDPR, but you must ensure user-consent for collecting location data. Anonymize or pseudonymize coordinates if storing user-specific geodata. Avoid storing raw API responses; extract only necessary fields for compliance.
How can I test this provider in Laravel without hitting the real GeoNames API?
Mock the HTTP client using Laravel’s `Http` facade or libraries like Mockery. Stub the GeoNames API endpoint in your tests to return predefined JSON responses. For example, use `Http::fake()` to intercept requests and assert expected behavior without real API calls.
What are the alternatives to this package, and when should I choose them?
Alternatives include `geocoder-php/nominatim-provider` (OpenStreetMap) for broader coverage or `geocoder-php/google-maps-provider` for Google’s API. Choose GeoNames if you need structured administrative divisions (e.g., ISO codes) or time zones. Use Nominatim for free, high-volume geocoding without API limits.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor