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.
Enable Google Air Quality API from GCP Console and create a new API Key
- iOS 17
- macOS 14
- tvOS 17
- watchOS 10
- File > Swift Packages > Add Package Dependency
- Add https://github.com/alfianlosari/XCAAQI.git
Initialize AirQualityClient
passing your Google API Key.
import XCAAQI
let aqiClient = AirQualityClient(apiKey: "YOUR_GOOGLE_API_KEY")
Task {
do {
let response = try await aqiClient.getCurrentCondition(latitude: -6.224856390623585, longitude: 106.80432119416706)
print(response)
} catch {
print(error.localizedDescription)
}
}
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)
}
}
- Current Condition Additional request parameters
- Historical data
- Heatmap data