- How do I integrate this Google Maps Places provider into a Laravel app?
- Install via Composer (`composer require geocoder-php/google-maps-places-provider`), then configure it in Laravel using GeocoderPHP. Example: `$geocoder = Geocoder::create(['google_maps_places' => ['key' => env('GOOGLE_MAPS_API_KEY')]]);` Bind it to Laravel’s service container for dependency injection.
- What Laravel versions does this package support?
- This provider works with Laravel 8.x, 9.x, and 10.x, assuming PHP 8.0+. Test with your Laravel LTS version (e.g., 10.x) for stability. PHP 8.2+ is recommended for newer features.
- How do I handle Google Places API quotas in production?
- Google’s free tier allows 40,000 requests/day. Cache responses in Redis (TTL: 1–24 hours) and implement fallback providers (e.g., OpenStreetMap) for overflow. Monitor usage via Google Cloud Console.
- Can I use this for autocomplete/search suggestions in Laravel?
- Yes. Use the `geocodeQuery` method with `GoogleMapsPlaces::GEOCODE_MODE_SEARCH` for flexible search results. Example: `$results = $provider->geocodeQuery(GeocodeQuery::create('coffee shop near me')->withData('mode', GoogleMapsPlaces::GEOCODE_MODE_SEARCH));`
- What’s the difference between 'find' and 'search' modes?
- 'Find' mode requires an exact place name and returns a single result (lower cost). 'Search' mode is forgiving but returns all fields (higher cost). Use 'search' for autocomplete or ambiguous queries.
- How do I store geocoded data (e.g., latitude/longitude) in Laravel?
- Use Eloquent casts like `Geocode` from `geocoder-php/geocoder-laravel` to auto-serialize coordinates. For geospatial queries, pair with PostgreSQL + PostGIS (e.g., `ST_DWithin` for radius searches).
- Is there a way to cache responses to reduce API calls?
- Yes. Use GeocoderPHP’s built-in caching (e.g., Redis) or Laravel’s cache system. Example: `$geocoder->setCache(new RedisCache());` Set TTLs based on data volatility (e.g., 1 hour for volatile, 24h for static places).
- What alternatives exist if Google Maps API costs exceed budget?
- Consider OpenStreetMap (`geocoder-php/openstreetmap-provider`), Mapbox, or Nominatim. These are free but may lack Google’s accuracy or structured place data. Test fallbacks with `Geocoder::create([...], 'fallback' => true)`.
- How do I handle API errors or rate limits in Laravel?
- Implement retry logic with exponential backoff (e.g., using `guzzlehttp/guzzle`). Log errors and notify users if geocoding fails. For rate limits, cache aggressively and monitor Google Cloud alerts.
- Does this package support reverse geocoding (coordinates to address)?
- Yes. Use the `reverseQuery` method: `$results = $provider->reverseQuery(GeocodeQuery::create(40.714224, -73.961452));` This returns structured place data (e.g., address components, place ID) for the given coordinates.