π Save time by finding optimal route for visiting multiple locations with real-time traffic data
π± NEW: Fully responsive design optimized for mobile, tablet, and desktop
A smart route optimization web application that uses advanced algorithms and Google Maps traffic data to minimize travel time when visiting multiple destinations. Features an intuitive tabbed interface for mobile devices and a powerful multi-column layout for desktop users.
- Nearest Neighbor Algorithm with 2-opt local search optimization
- Real-time traffic-aware routing using Google Maps Distance Matrix API
- Flexible routing: start only, end only, both, or neither
- Automatic waypoint reordering for maximum efficiency
- Add unlimited waypoints (addresses/locations)
- Optional starting point and destination
- Visual map with numbered markers
- Real-time geocoding with address validation
- Fully Responsive Design - Optimized for desktop, tablet, and mobile
- Desktop Features:
- 3-column layout with collapsible sidebar
- Toggle sidebar with β button for more map space
- Side-by-side results panel
- Mobile Features (NEW β¨):
- Intuitive tabbed interface (Locations | Map | Route)
- Full-screen map view
- Bottom sheet for route details
- Large touch targets (44x44px minimum)
- Auto-switch to map after optimization
- Instant route visualization on Google Maps
- Detailed route summary with:
- Total travel distance
- Total travel time (with live traffic)
- Step-by-step directions with leg distances and times
| Component | Technology |
|---|---|
| Backend | Flask 2.0+ (Python 3.9+) |
| Frontend | Vanilla JavaScript + CSS3 (Responsive) |
| Design | Mobile-first responsive (breakpoints: 480px, 768px, 1200px) |
| Maps | Google Maps JavaScript API |
| Traffic | Google Distance Matrix API (TrafficModel.BEST_GUESS) |
| Geocoding | Google Geocoding API |
| Deployment | Render (Free tier) |
- Python 3.9 or higher
- Google Maps API key with enabled services:
- Maps JavaScript API
- Directions API
- Distance Matrix API
- Geocoding API
-
Clone the repository
git clone https://github.com/gatorbonita/route-optimizer.git cd route-optimizer -
Install dependencies
pip install -r requirements.txt
-
Configure Google Maps API
Open
templates/index.htmland update the API key (line ~281):const API_KEY = 'YOUR_GOOGLE_MAPS_API_KEY_HERE';
-
Run the application
python app.py
-
Open in browser Navigate to: http://localhost:5000
To test the mobile experience on your phone:
-
Find your computer's IP address
ipconfig | findstr "IPv4" # Look for something like: 192.168.1.XXX
-
Make sure your phone is on the same WiFi network
-
Update Google Maps API Key restrictions
- Go to Google Cloud Console
- Add your local IP to HTTP referrers:
http://192.168.1.*:5000/*
-
Open on your phone
- Navigate to:
http://YOUR-IP:5000(e.g.,http://192.168.1.157:5000) - You'll see the mobile tabbed interface!
- Navigate to:
Alternative: Deploy to Render (free) for permanent public access - see Deployment section
-
Add Locations
- Enter addresses in the "Waypoints" field
- Click "+ Add Waypoint" to add each location
- Optionally specify a starting point and/or destination
-
Choose Optimization Priority
- β±οΈ Fastest: Routes based on real-time traffic
- π Shortest: Routes based on geographic distance
-
Optimize
- Click "π Optimize Route"
- Wait for route calculation (uses real-time traffic data)
- View the optimized route on the map
-
Follow the Route
- Numbered markers show optimal visitation order
- Route summary displays total distance and time
- Each leg shows distance, time, and live traffic status
-
Maximize Map Space (Optional)
- Click the β button on the sidebar edge to collapse it
- Click βΆ to expand it back
The mobile interface uses a tabbed layout for optimal screen usage:
-
π Locations Tab - Add and manage your waypoints
- Tap on the Locations tab
- Add addresses using the input field
- Set optional start/end points
-
πΊοΈ Map Tab - View your route
- After optimization, automatically switches to map
- Full-screen map display
- Pinch to zoom, drag to pan
-
π Route Tab - View route details
- Tap to see detailed route information
- Bottom sheet slides up with results
- Swipe or tap Γ to close
- Use specific addresses for better geocoding accuracy
- Try different optimization priorities for different scenarios
- Peak hours may show longer travel times due to traffic
- Route optimization works best with 5-15 locations
- On mobile, landscape orientation provides more map space
-
Push to GitHub
git add . git commit -m "Ready for deployment" git push origin main
-
Create Render Web Service
- Go to render.com
- Click "New +" β "Web Service"
- Connect your GitHub repository
- Configure:
- Runtime: Python 3
- Build Command:
pip install -r requirements.txt - Start Command:
python app.py
- Click "Create Web Service"
-
Set Environment Variables (Optional but recommended)
FLASK_ENV=production FLASK_DEBUG=0 PORT=5000 -
Configure Google Maps API Key
- Add your Render URL to the API key HTTP referrers
- Format:
https://your-app-name.onrender.com/*
Your app will be available at: https://your-app-name.onrender.com
- Railway: railway.app
- PythonAnywhere: pythonanywhere.com
| Variable | Description | Default |
|---|---|---|
FLASK_ENV |
Flask environment | development |
FLASK_DEBUG |
Enable debug mode | True |
PORT |
Server port | 5000 |
- Go to Google Cloud Console
- Create a new project or select existing
- Enable required APIs:
- Maps JavaScript API
- Directions API
- Distance Matrix API
- Geocoding API
- Create credentials (API Key)
- Add application referrers for security:
- Development:
http://localhost:5000/* - Production:
https://your-app-name.onrender.com/*
- Development:
The app uses a two-phase optimization algorithm:
-
Nearest Neighbor Greedy Algorithm
- Starts from a point and repeatedly visits the nearest unvisited location
- Tries multiple starting points to find the best initial route
- Handles four scenarios:
- Fixed start + fixed end
- Start only
- End only
- No constraints (circular route)
-
2-opt Local Search
- Takes the greedy solution and iteratively improves it
- Swaps route segments if it reduces total travel time
- Continues until no improvements can be found
The app builds an NΓN matrix where N = total locations:
matrix[i][j] = travel time from location i to location j
This matrix enables O(1) lookups during optimization.
- Distance Matrix: O(NΒ²) API calls
- Nearest Neighbor: O(NΒ²)
- 2-opt Optimization: O(NΒ³) in worst case
- Practical: Works well for 5-15 locations
| Service | Free Tier Limit | Unit |
|---|---|---|
| Distance Matrix API | 100,000 | elements/day |
| Directions API | 10,000 | requests/day |
| Geocoding API | 40,000 | requests/day |
π‘ Note: 1 Distance Matrix request with 4 locations = 16 elements (4Γ4 matrix)
App shows "Google Maps Error"
- Check the API key is correct and not restricted
- Ensure all required APIs are enabled in Google Cloud Console
- Verify your domain is added to API key HTTP referrers
Route optimization is slow
- First API call may take 10-30 seconds
- Ensure billing is enabled on your Google Cloud project
- Try fewer locations (<10 for faster performance)
Map markers don't display
- Check browser console for JavaScript errors
- Verify the API key has Maps JavaScript API enabled
- Clear browser cache and reload
Mobile device can't connect (RefererNotAllowedMapError)
- Ensure phone is on the same WiFi as your computer
- Add your local IP to API key HTTP referrers (e.g.,
http://192.168.1.*:5000/*) - Wait 1-2 minutes after updating API key restrictions
- For production, deploy to Render and add that URL to referrers
Tabs not switching on mobile
- Hard refresh the page (Ctrl+Shift+R or Cmd+Shift+R)
- Clear browser cache
- Check if JavaScript is enabled
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
git clone https://github.com/gatorbonita/route-optimizer.git
cd route-optimizer
pip install -r requirements.txt
python app.pyThis project is licensed under the MIT License - see the LICENSE file for details.
Route Optimizer - Built with β€οΈ to help save time on the road
- Google Maps Platform - Maps, Directions, and Distance Matrix APIs
- Flask - Web framework
- Render - Free hosting platform
Made with β€οΈ by Route Optimizer Team