PinCodeDistance API calculates the distance (in kilometers) and estimated travel duration between two Indian pincodes using the Google Maps API.
- Fetches latitude & longitude for a given pincode.
- Calculates Haversine distance between two pincodes.
- Fetches real-world distance and travel time using Google Maps Distance Matrix API.
- Logs API calls and errors for debugging.
- .NET 6 or later
- Google Cloud API Key with Geocoding and Distance Matrix API enabled
- Clone the repository:
git clone https://github.com/yourusername/PinCodeDistance.git cd PinCodeDistance - Install dependencies:
dotnet restore
- Set up your Google API Key in
appsettings.json:{ "GoogleApiKey": "YOUR_GOOGLE_MAPS_API_KEY" } - Run the application:
dotnet run
Endpoint:
POST /api/pincode/distance
Request Body:
{
"OriginPincode": "110001",
"DestinationPincode": "560001"
}Response:
{
"distance": 1740,
"duration": "30h 15m",
"distanceUnit": "km",
"status": {
"Code": 200,
"text": "success"
}
}Endpoint:
POST /api/pincode/distancev2
Request Body:
{
"OriginPincode": "110001",
"DestinationPincode": "560001"
}Response:
{
"distance": 1740,
"distanceUnit": "km",
"status": {
"Code": 200,
"text": "success"
}
}- Fetch Geolocation:
- Calls Google Geocoding API to retrieve latitude & longitude for each pincode.
- Calculate Distance:
- Uses the Haversine formula for straight-line distance.
- Calls Google Distance Matrix API for real-world travel distance & duration.
- Return Response:
- Returns distance (km) and estimated travel time.
- .NET 6 (C#)
- Google Maps APIs (Geocoding + Distance Matrix)
- Newtonsoft.Json for JSON handling
- Serilog for logging
This project is licensed under the MIT License.
- Fork the repository.
- Create a new branch (
feature-branch). - Commit changes and push.
- Open a Pull Request!
For questions, reach out at [email protected] or open an issue on GitHub!