Address Autocomplete Feature
Overview
The property dialog now includes Google Places Autocomplete for improved address entry. This provides a better user experience by suggesting addresses as users type.Setup
1. Get a Google Maps API Key
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Maps JavaScript API ✅ (Required for loading Google Maps)
- Places API (New) ✅ (Required for autocomplete)
- Create credentials (API Key)
- Restrict the API key to your domain for production
2. Configure Environment Variable
Add the following to your.env.local file:
NEXT_PUBLIC_ prefix is required for client-side access in Next.js.
3. API Key Restrictions (Recommended for Production)
For security, restrict your API key: Application Restrictions:- Set HTTP referrers to your domains:
https://yourdomain.com/*http://localhost:3000/*(for development)
- Only allow:
- Maps JavaScript API (loads the script)
- Places API (New) (provides autocomplete)
Features
- Real-time suggestions as user types (debounced to 300ms)
- US address filtering - restricts results to US addresses only
- Session tokens - optimizes API usage and reduces costs
- Fallback - If API key is missing, component falls back to regular input
- Loading states - Shows spinner while loading script and fetching suggestions
- Click outside - Closes suggestions dropdown when clicking elsewhere
Cost Optimization
The component uses several techniques to minimize API costs:- Debouncing - Waits 300ms after user stops typing before making API call
- Session tokens - Groups autocomplete + place details requests into single session (cheaper billing)
- Minimum characters - Only searches after user types 3+ characters
- Request optimization - Only requests necessary fields in place details
Pricing
As of 2024:- Autocomplete - Per Session: $2.83 per 1000 requests
- Place Details - Basic: $0.00 per 1000 requests (when bundled with Autocomplete)
Usage
The AddressAutocomplete component is used in TWO places:1. Property Search Tab
Users can:- Start typing an address
- Select from suggested addresses
- The full address is auto-filled
- Then search for property details via Zillow
2. Manual Entry Tab
Users can:- Start typing in the Street Address field
- Select from suggested addresses
- All address fields auto-fill (street, city, state, zip)
- Then add property with manual estimated value
Troubleshooting
Error: “ApiTargetBlockedMapError”
This means your API key has referrer restrictions that are blocking localhost. Solution:- Go to Google Cloud Console
- Click on your API key
- Under “Application restrictions” → “HTTP referrers”
- Add these referrers:
- Save changes (may take a few minutes to propagate)
Autocomplete not working
- Check console for errors - Look for API key issues
- Verify API is enabled - Ensure Places API is enabled in Google Cloud
- Check billing - Ensure billing is set up on your Google Cloud project
- Verify environment variable - Make sure
NEXT_PUBLIC_GOOGLE_MAPS_API_KEYis set in.env.local - Restart dev server - After adding env variable:
npm run dev
Component shows regular input (no autocomplete)
The component automatically falls back to a regular input field if:- API key is not set
- API key is invalid or blocked
- Google Maps script fails to load
Manual Input Fallback
Both the Property Search and Manual Entry tabs support manual input. If autocomplete fails or API key is not configured:- Users can still type addresses manually
- The component gracefully falls back to a regular text input
- All functionality remains available