AndrewJBateman / ionic-angular-weatherapi

:clipboard: App to display weather data from a weather API using the Ionic 5 framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ionic Angular WeatherApi

  • App to display weather data from the Weatherstack weather API using the Ionic framework.
  • Some changes were made to the code so it would work in the latest Angular version.
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size GitHub pull requests GitHub Repo stars GitHub last commit

Table of contents

πŸ“š General info

  • The Weatherstack weather API is a fully managed weather API platform that provides extensive APIs that supply the following data:

  • Real-time weather

  • Up to 14 day weather forecast

  • Historical weather inforamtion

  • Astronomy

  • Time zone

  • Geolocation data

πŸ“· Screenshots

Ionic page

πŸ“Ά Technologies

πŸ’Ύ Setup

  • npm i to install dependencies
  • Get yourself an API key from weatherstack.com and add to weather.service.ts line 4
  • To start the server on localhost://8100 type: 'ionic serve'

πŸ’» Code Examples

  • Extract from weather.service.ts that gets data from the API.
export class WeatherService {

  constructor(private httpClient: HttpClient) {}

  getWeatherFromApi(city: string) {
    return this.httpClient.get(`http://api.weatherstack.com/current?access_key=${apiKey}&query=${city}`);
  }
}
  • Extract from list.page.ts function to get API weather data.
getWeather() {
  this.ionicStorage.get('city').then( city => {
    if (city === null) {
      this.weatherService.getWeatherFromApi('madrid').subscribe( weather => {
        this.weather = weather;
        console.log(weather);
      });
    } else {
      this.weatherService.getWeatherFromApi(city).subscribe( weather => {
        this.weather = weather;
        console.log(weather);
      });
    }

  }).catch(err => {
    console.log(err);
  });
}

πŸ†’ Features

  • Searches for weather data in any city of the world
  • Ionic storage module used

πŸ“‹ Status & To-do list

  • Status: Working.
  • To-do: Add to menu options - list of cities searched for etc. Convert to use Angular async pipe

πŸ‘ Inspiration

πŸ“ License

  • This project is licensed under the terms of the MIT license.

βœ‰οΈ Contact

About

:clipboard: App to display weather data from a weather API using the Ionic 5 framework.

License:MIT License


Languages

Language:TypeScript 60.5%Language:SCSS 21.4%Language:HTML 11.2%Language:JavaScript 7.0%