How geolocation works
When you first visit Coffee Finder, the application:- Requests permission to access your location
- Retrieves high-accuracy GPS coordinates
- Centers the map on your position
- Fetches nearby coffee shops within an 8km radius
- Displays your location with a distinct marker
The geolocation feature requires browser permission. Users will see a permission prompt on their first visit.
Location state management
The application tracks location state using a dedicated interface:src/app/page.tsx
User experience flows
- First visit
- Permission denied
- User lands on Coffee Finder
- Browser displays permission prompt: “Allow Coffee Finder to access your location?”
- User grants permission
- Loading indicator appears: “Getting your location…”
- Map centers on user’s coordinates
- Nearby coffee shops appear on the map and in the sidebar
Implementation details
ThegetCurrentLocation function handles all location retrieval logic:
src/app/page.tsx
Configuration options
The geolocation request uses these settings:enableHighAccuracy: true
enableHighAccuracy: true
Requests the most accurate position available, typically using GPS. This provides better precision for finding nearby coffee shops but may take longer and consume more battery.
timeout: 10000
timeout: 10000
Sets a 10-second maximum wait time for location detection. If the device cannot determine location within this timeframe, a timeout error is triggered.
maximumAge: 0
maximumAge: 0
Prevents using cached location data, ensuring the freshest possible coordinates. This is essential for accurate “nearby” results.
Error handling
Coffee Finder provides specific error messages for different failure scenarios:| Error Code | User Message | Common Cause |
|---|---|---|
PERMISSION_DENIED | Location permission denied. Please enable location access. | User declined permission or browser settings block access |
POSITION_UNAVAILABLE | Location information is unavailable | GPS signal is weak, device is indoors, or location services are disabled |
TIMEOUT | Location request timed out | Network issues or slow GPS acquisition |
| Browser not supported | Geolocation is not supported by your browser | Using an outdated browser |
Refresh location
Users can manually refresh their location at any time:src/app/page.tsx
- Shows a loading spinner during location detection
- Disables to prevent multiple simultaneous requests
- Re-fetches coffee shops after getting new coordinates
- Updates the map center to the new location
Automatic initialization
Location detection starts automatically when the app loads:src/app/page.tsx
src/app/page.tsx
This automatic flow ensures users see relevant coffee shops immediately after granting location permission, creating a seamless discovery experience.
Browser compatibility
The Geolocation API is supported in all modern browsers:- Chrome 5+
- Firefox 3.5+
- Safari 5+
- Edge (all versions)
- Opera 10.6+
- Mobile browsers (iOS Safari, Chrome Mobile)