Your PlaceService.swift has been updated to use the new Google Places API (New). The changes include:
- Old:
https://maps.googleapis.com/maps/api/place/autocomplete/json - New:
https://places.googleapis.com/v1/places:autocomplete - Method: Changed from GET to POST with JSON body
- Headers: Added
X-Goog-Api-KeyandContent-Type: application/json
- Old:
https://maps.googleapis.com/maps/api/place/details/json - New:
https://places.googleapis.com/v1/places/{PLACE_ID} - Headers: Added
X-Goog-Api-KeyandX-Goog-FieldMask
- Go to Google Cloud Console APIs
- Search for "Places API (New)"
- Click on it and press "Enable"
- Go to API Keys
- Click on your API key
- Under "Application restrictions":
- Select "HTTP referrers"
- Add
https://hushmap.app/*as an authorized referrer - For development, add
http://localhost:*/*(optional)
- Under "API restrictions":
- Add "Places API (New)" to the list of restricted APIs
⚠️ CRITICAL SECURITY WARNING: Unrestricted API keys will lead to unauthorized usage and additional billing charges. Google will send warning emails for unrestricted keys. See API_KEY_SECURITY.md for details.
- You can now disable the legacy "Places API" since we're using the new one
- This won't affect your implementation
After enabling the new API, test by:
- Opening the app
- Tapping the Search button in the top menu
- Typing a place name (e.g., "Preston")
- You should see autocomplete suggestions without errors
The main changes preserve the same interface but use the new API format:
- Request Format: Now uses JSON POST requests with proper headers
- Response Parsing: Updated to handle the new JSON structure
- Field Names: Updated to match new API field names (
displayName.textvsname) - Location Data: Updated path (
location.latitudevsgeometry.location.lat)
This update demonstrates:
- Modern API Usage: Using the latest Google Places API
- Best Practices: Proper error handling and request formatting
- Technical Excellence: Professional API integration suitable for awards submission