spatie/google-time-zone
Convert GPS coordinates to time zone data using Google's Time Zone service. Get DST offset, raw offset, time zone ID, and time zone name from latitude and longitude. Works in plain PHP and Laravel projects, with a publishable config for your Google Maps API key and language setting.
timeZoneId, rawOffset, dstOffset, timeZoneName), enabling downstream use cases like:
Cache::remember). Can be extended via Laravel’s service providers or event system (e.g., TimeZoneUpdated events).Cache::forever() or database storage).GoogleTimeZone::getTimeZoneForCoordinates() for simplicity or inject the service directly for testing.TimeZoneResolved) for side effects (e.g., updating user profiles).Mockery or PHPUnit to stub Google’s API responses in tests.composer.json constraints).composer require spatie/google-time-zone..env (e.g., GOOGLE_TIMEZONE_API_KEY).app/Services/TimeZoneService) for abstraction.Cache::remember).coordinates_hash as a composite key).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Google API downtime | Time zones unavailable | Fallback to cached data or manual overrides. |
| API key quota exceeded | Requests fail | Implement retry logic with exponential backoff. |
| Invalid coordinates | Incorrect time zones | Validate inputs; log and alert on anomalies. |
| Time zone data staleness (e.g., DST) | Outdated time zones | Schedule cache invalidation; monitor updates. |
| High API latency | Slow UI responses | Cache responses; pre-fetch for known locations. |
How can I help you explore Laravel packages today?