This React application allows users to check the current weather by entering either a city name or a pincode. It utilizes the OpenWeatherMap API to fetch weather data based on the provided city name. If a pincode is entered, it first fetches the corresponding city name using the Google Maps Geocoding API and then retrieves weather information.
-
Clone the repository: git clone <repository_url>
-
Navigate to the project directory: cd <project_directory>
-
Install dependencies: npm install
-
Set up environment variables:
- Get an API key from OpenWeatherMap and replace
'YOUR_OPENWEATHERMAP_API_KEY'
with your API key in thegetWeather()
function. - Get an API key from Google Maps and replace
'YOUR_GOOGLE_API_KEY'
with your API key in thegetWeatherByPincode()
function.
- Run the application: npm start
- Enter a city name in the input field and click "Get Weather" to fetch the weather details for the specified city.
- Alternatively, enter a pincode in the input field and click "Get Weather" to retrieve the weather information based on the corresponding city.
- React.js
- useState Hook for managing component state
- Fetch API for making HTTP requests
- OpenWeatherMap API for weather data
- Google Maps Geocoding API for converting pincode to city name
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -am 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new Pull Request.
This project is licensed under the terms of the MIT license. Replace 'YOUR_OPENWEATHERMAP_API_KEY' and 'YOUR_GOOGLE_API_KEY' with your respective API keys
https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=1b4de0d3fd5f51d4669f87a945488671