A Spring Boot application that calculates toll plazas between two Indian pincodes using Google Maps APIs and geometric calculations.
- Calculate distance between two Indian pincodes using Google Distance Matrix API
- Find toll plazas along the route using geometric corridor detection
- Response caching for frequently queried routes
- Input validation for Indian pincodes
- Automatic loading of toll plaza data from CSV file
- Java 21
- MySQL 8.0+
- Maven 3.9+
- Google Maps API key with:
- Distance Matrix API enabled
- Geocoding API enabled
-
Clone the repository
git clone https://github.com/Somtrip/toll-between-pincodes.git cd toll-between-pincodes/ -
Database Setup
CREATE DATABASE toll_plaza_route;
-
Configure Environment Variables Update
src/main/resources/application.properties:spring.datasource.password=your_mysql_password google.api.key=your_google_maps_api_key
-
Build the Application
./mvnw clean package
./mvnw spring-boot:runThe application will start on http://localhost:8080
Endpoint: POST /api/v1/toll-plazas
Request Body:
{
"sourcePincode": "560064",
"destinationPincode": "411045"
}Example using Postman:
- Set request method to POST
- Set URL:
http://localhost:8080/api/v1/toll-plazas - Set Headers:
Content-Type: application/json
- Set Body (raw JSON):
{ "sourcePincode": "560064", "destinationPincode": "411045" }
Example Response:
{
"route": {
"sourcePincode": "560064",
"destinationPincode": "411045",
"distanceInKm": 855.8
},
"tollPlazas": [
{
"name": "Devanahalli Toll Plaza",
"latitude": 13.1936004,
"longitude": 77.6472356,
"distanceFromSource": 35.2,
"geoState": "Karnataka"
},
{
"name": "Hirekodige Toll Plaza",
"latitude": 13.5175,
"longitude": 77.495,
"distanceFromSource": 62.1,
"geoState": "Karnataka"
}
]
}src/
├── main/
│ ├── java/
│ │ └── com/som/toll/
│ │ ├── client/ # Google Maps API client
│ │ ├── controller/ # REST controllers
│ │ ├── dto/ # Data transfer objects
│ │ ├── entity/ # JPA entities
│ │ ├── loader/ # CSV data loader
│ │ ├── repository/ # Data repositories
│ │ ├── service/ # Business logic
│ │ └── util/ # Utility classes
│ └── resources/
│ ├── application.properties
│ └── toll_plaza_india.csv # Toll plaza database
└── test/ # Unit tests
- Invalid Pincode Errors: Ensure pincodes are valid 6-digit Indian pincodes
- API Key Errors: Verify Google Maps API key has correct permissions
- Database Connection: Check MySQL is running and credentials are correct
- CORS Issues: Configure CORS if accessing from different domains
- Java 21
- Spring Boot 3.5.4
- MySQL Database
- Google Maps APIs
- Maven
- Lombok
- JPA/Hibernate