alfianlosari / XCAAQI

Google AQI API Swift Client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XCAAQI

alt text

Unofficial Google Air Quality API Swift Client.

You can use it to fetch current AQI Conditions given a coordinate, it provides:

  • Air Quality Index (UAQI).
  • Dominant Pollutant.
  • Color.
  • Air Quality Condition.

Requirements

Enable Google Air Quality API from GCP Console and create a new API Key

  • iOS 17
  • macOS 14
  • tvOS 17
  • watchOS 10

Installation

Swift Package Manager

Usage

Initialize AirQualityClient passing your Google API Key.

import XCAAQI

let aqiClient = AirQualityClient(apiKey: "YOUR_GOOGLE_API_KEY")

Fetch current AQ condition given a coordinate

Task {
    do {
        let response = try await aqiClient.getCurrentCondition(latitude: -6.224856390623585, longitude: 106.80432119416706)
        print(response)
    } catch {
        print(error.localizedDescription)
    }
}

Fetch current AQ condition given array of coordinates

Note: Each of element in array will account to 1 API call to Google AQI API. If you have 20 coordinates, it will count toward 20 API call in your billing usage.

Task {
    do {
        let responses = try await aqiClient.getCurrentConditions(coordinates: [
            (-6.224856390623585, 106.80432119416706),
            (-5.224856390623585, 103.80432119416706)
        ])
        print(responses)
    } catch {
        print(error.localizedDescription)
    }
}

TODO

  • Current Condition Additional request parameters
  • Historical data
  • Heatmap data

About

Google AQI API Swift Client

License:MIT License


Languages

Language:Swift 100.0%