### Request Example Source: https://dev.qweather.com/en/docs/api/geoapi/poi-range Example of how to make a GET request to the POI Range API. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/geo/v2/poi/range?location=116.40528,39.90498&type=scenic&radius=10' ``` -------------------------------- ### Tide API Request Example Source: https://dev.qweather.com/en/docs/api/ocean/tide Example of how to make a GET request to the Tide API with required parameters. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/ocean/tide?location=P2951&date=20210206' ``` -------------------------------- ### Moon and Moon Phase API Request Example Source: https://dev.qweather.com/en/docs/api/astronomy/moon-and-moon-phase Example of how to make a GET request to the Moon and Moon Phase API. Replace 'your_token' and 'your_api_host' with your actual credentials and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/astronomy/moon?location=101010100&date=20211120' ``` -------------------------------- ### Install dependencies with CocoaPods Source: https://dev.qweather.com/en/docs/configuration/ios-sdk-config Run this command in the terminal after creating or modifying your Podfile to install the SDK. ```bash pod install ``` -------------------------------- ### Example API Host Source: https://dev.qweather.com/en/docs/configuration/api-host This is an example of a unique API Host provided for a developer account. It should be used in API URLs or SDK configurations. ```text abc1234xyz.def.qweatherapi.com ``` -------------------------------- ### cURL Request Example Source: https://dev.qweather.com/en/docs/api/astronomy/solar-elevation-angle Example of how to make a GET request to the Solar Elevation Angle API using cURL. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/astronomy/solar-elevation-angle?location=120.34,36.08&alt=43&date=20210220&time=1230&tz=0800' ``` -------------------------------- ### Example Public Key Format Source: https://dev.qweather.com/en/docs/configuration/project-and-key This is an example of the public key format used for JWT credentials. Ensure the entire content is copied. ```text -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAARbeZ5AhklFG4gg1Gx5g5bWxMMdsUd6b2MC4wV0/M9Q= -----END PUBLIC KEY----- ``` -------------------------------- ### Solar Radiation Forecast Request Example Source: https://dev.qweather.com/en/docs/api/solar-radiation/solar-radiation-forecast Example using cURL to request solar radiation forecast data. Replace placeholders with your actual token and API host. ```bash curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/solarradiation/v1/forecast/50.11/8.68' ``` -------------------------------- ### Weather Hourly Forecast Request Example Source: https://dev.qweather.com/en/docs/api/weather/weather-hourly-forecast Example of how to request hourly weather data for a specific location and duration. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/weather/24h?location=101010100' ``` -------------------------------- ### cURL Request Example Source: https://dev.qweather.com/en/docs/api/geoapi/top-city Example of how to make a request to the Top City endpoint using cURL. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/geo/v2/city/top?number=5&range=cn' ``` -------------------------------- ### Initialize QWeather Instance in Swift Source: https://dev.qweather.com/en/docs/configuration/ios-sdk-config Initialize the QWeather API host and enable debug logging in Swift. Replace YOUR_HOST with your actual API host. ```swift import QWeatherSDK ... try await QWeather .getInstance("{YOUR_HOST}") // Initialize api host .setupLogEnable(true) // Enable debug logging (set false for production environments) ``` -------------------------------- ### Initialize QWeather Instance Source: https://dev.qweather.com/en/docs/configuration/android-sdk-config Initialize the QWeather SDK instance with your API host. Debug logging can be enabled or disabled. ```java QWeather.getInstance(MainActivity.this, "{YOUR_HOST}") // Initialize api host .setLogEnable(true); // Enable debug logging (set false for production environments) ``` -------------------------------- ### Curl Request Example Source: https://dev.qweather.com/en/docs/api/geoapi/poi-lookup Example of how to make a GET request to the POI Lookup API using curl. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/geo/v2/poi/lookup?type=scenic&location=jings' ``` -------------------------------- ### Initialize QWeather Instance in Objective-C Source: https://dev.qweather.com/en/docs/configuration/ios-sdk-config Initialize the QWeather API host and enable debug logging in Objective-C. Replace YOUR_HOST with your actual API host. ```objectivec #import ... // Initialize api host [QWeatherObjc initConfigWithHost:@"{YOUR_HOST}"]; // Enable debug logging (set false for production environments) [QWeatherObjc setupLogEnable:YES]; ``` -------------------------------- ### POI Range API Endpoint Source: https://dev.qweather.com/en/docs/api/geoapi/poi-range This snippet details the GET request for the POI Range API, including its endpoint, parameters, and example usage. ```APIDOC ## GET /geo/v2/poi/range ### Description Queries all POI information within a specified area. ### Method GET ### Endpoint /geo/v2/poi/range ### Parameters #### Query Parameters - **location** (string) - Required - The comma-separated longitude and latitude (decimal, up to 2 decimal places) of the location to be queried. For example: `location=116.41,39.92` - **type** (string) - Required - Choose to search for a certain type of POI. Possible values: `scenic`, `TSTA`. - **radius** (integer) - Optional - Set search radius, the value range is 1-50, in kilometers. Defaults to 5. - **number** (integer) - Optional - Number of the results in response, from 1 to 20. Defaults to 10. - **lang** (string) - Optional - Multi-language setting. Please refer to the Language documentation for details. ### Request Example ``` curl -X GET --compressed \ -H "Authorization: Bearer your_token" \ 'https://your_api_host/geo/v2/poi/range?location=116.40528,39.90498&type=scenic&radius=10' ``` Replace `your_token` and `your_api_host` with your JWT Authentication and API Host. ### Response #### Success Response (200) The response is in JSON format and is Gzip compressed. - **code** (string) - Status code. - **poi** (array) - An array of POI objects. - **name** (string) - POI Name. - **id** (string) - POI ID. - **lat** (string) - Latitude of the POI. - **lon** (string) - Longitude of the POI. - **adm2** (string) - Name of the superior administrative division of the POI. - **adm1** (string) - The first-level administrative area of the POI. - **country** (string) - Country name of the POI. - **tz** (string) - POI timezone. - **utcOffset** (string) - The number of hours offset between local time and UTC time. - **isDst** (string) - Indicates if the POI is currently on daylight saving time (`1` for yes, `0` for no). - **type** (string) - POI type. - **rank** (string) - POI Rank. - **fxLink** (string) - Responsive web page of this location. - **refer** (object) - Data source and other statements. - **sources** (array) - Data source. - **license** (array) - Data license. #### Response Example ```json { "code": "200", "poi": [ { "name": "中山公园", "id": "10101010016A", "lat": "39.90999985", "lon": "116.38999939", "adm2": "北京", "adm1": "北京", "country": "中国", "tz": "Asia/Shanghai", "utcOffset": "+08:00", "isDst": "0", "type": "scenic", "rank": "86", "fxLink": "https://www.qweather.com" } ], "refer": { "sources": ["QWeather"], "license": ["QWeather Developers License"] } } ``` ``` -------------------------------- ### Reference Libraries Source: https://dev.qweather.com/en/docs/configuration/android-sdk-config Include necessary third-party libraries like OkHttp, Gson, and EDDSA for SDK functionality. ```gradle implementation 'com.squareup.okhttp3:okhttp:4.12.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'net.i2p.crypto:eddsa:0.3.0' ``` -------------------------------- ### Calculate Monthly Cost for 2 Million Requests Source: https://dev.qweather.com/en/docs/finance/billing-and-payment Example calculation for a scenario with 1 million weather API requests and 1 million warning API requests in a month, demonstrating tiered pricing application. ```text 50,000 requests x CNY 0 + 950,000 requests x CNY 0.0007 + 1,000,000 requests x CNY 0.0005 = CNY 1,165 ``` -------------------------------- ### Generate JWT with Python 3 Source: https://dev.qweather.com/en/docs/configuration/authentication This Python 3 example utilizes the `cryptography` and `PyJWT` libraries to generate a JWT. You need to install them using `pip3 install cryptography PyJWT`. The code shows how to load the private key, define the payload and headers, and then encode the JWT. ```Python #!/usr/bin/env python3 import sys import time import jwt # Open PEM private_key = """YOUR_PRIVATE_KEY""" payload = { 'iat': int(time.time()) - 30, 'exp': int(time.time()) + 900, 'sub': 'YOUR_PROJECT_ID' } headers = { 'kid': 'YOUR_KEY_ID' } # Generate JWT encoded_jwt = jwt.encode(payload, private_key, algorithm='EdDSA', headers = headers) print(f"JWT: {encoded_jwt}") ``` -------------------------------- ### Request Tropical Cyclone Storm List Source: https://dev.qweather.com/en/docs/api/tropical-cyclone/storm-list Example of how to make a GET request to the storm-list API. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/tropical/storm-list?basin=NP&year=2020' ``` -------------------------------- ### Request Weather Alert Data Source: https://dev.qweather.com/en/docs/api/warning/weather-alert Example of how to make a GET request to the Weather Alert API to retrieve current severe weather alerts. Replace placeholders with your actual token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/weatheralert/v1/current/39.90/116.40' ``` -------------------------------- ### Get Real-Time Weather (Objective-C) Source: https://dev.qweather.com/en/docs/configuration/ios-sdk-config Fetches current weather data for a specified location using the QWeather SDK in Objective-C. Ensure the SDK is imported and initialized. ```objectivec #import ... WeatherParameter *parameter = [WeatherParameter instanceWithLocation:@"101010100" lang:@(LangZH_HANS) unit:@(UnitMETRIC)]; [QWeatherObjc weatherNow:parameter completionHandler:^(WeatherNowResponse * _Nullable response, NSError * _Nullable error) { if (response) { NSLog(@"%@", response.description); } if (error) { NSLog(@"%@", error.localizedDescription); } }]; ``` -------------------------------- ### Sunrise and Sunset API Request Example Source: https://dev.qweather.com/en/docs/api/astronomy/sunrise-sunset This snippet shows how to make a GET request to the Sunrise and Sunset API. Replace `your_token` and `your_api_host` with your actual JWT authentication token and API host. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/astronomy/sun?location=101010100&date=20210220' ``` -------------------------------- ### Configure ProGuard Rules Source: https://dev.qweather.com/en/docs/configuration/android-sdk-config Add these rules to your `proguard-rules.pro` file to prevent the QWeather SDK classes from being obfuscated. ```proguard -keep public class com.qweather.sdk.QWeather { public *; } -keep public class com.qweather.sdk.basic.**{ *; } -keepclassmembers class com.qweather.sdk.basic** { *; } -keep public class com.qweather.sdk.parameter.**{ *; } -keepclassmembers class com.qweather.sdk.parameter** { *; } -keep public class com.qweather.sdk.response.**{ *; } -keepclassmembers class com.qweather.sdk.response** { *; } -keep interface com.qweather.sdk.Callback{ *; } -keep interface com.qweather.sdk.TokenGenerator{ *; } -keep public class com.qweather.sdk.JWTGenerator { public *; } ``` -------------------------------- ### Get Air Quality Daily Forecast (Objective-C) Source: https://dev.qweather.com/en/docs/ios-sdk/air-quality/ios-air-daily-forecast This Objective-C code snippet demonstrates how to retrieve daily air quality forecasts. It includes parameter setup and a completion handler for processing the response or errors. ```Objective-C AirV1Parameter *parameter = [AirV1Parameter instanceWithLongitude:116.41 latitude:39.92 lang:@(LangZH_HANS)]; [QWeatherObjc airDaily:parameter completionHandler:^(AirV1DailyResponse * _Nullable response, NSError * _Nullable error) { if (response) { NSLog(@"%@", response.description); } if (error) { NSLog(@"%@", error.localizedDescription); } }]; ``` -------------------------------- ### Get 1-Day Weather Indices Forecast Source: https://dev.qweather.com/en/docs/api/indices/indices-forecast This example demonstrates how to request a 1-day forecast for specific weather indices (e.g., sports and car wash) for a given location ID. Ensure you replace 'your_token' and 'your_api_host' with your actual credentials. ```curl curl -X GET --compressed \ -H 'Authorization: Bearer your_token' \ 'https://your_api_host/v7/indices/1d?type=1,2&location=101010100' ``` -------------------------------- ### Java Indices Example Source: https://dev.qweather.com/en/docs/resource/indices-info Example of how to use the SPT (Sports) index in Java. ```Java Indices indices = Indices.SPT; ``` -------------------------------- ### Objective-C Indices Example Source: https://dev.qweather.com/en/docs/resource/indices-info Example of how to use the SPT (Sports) index in Objective-C. ```Objective-C Indices indices = IndicesSPT; ``` -------------------------------- ### Calculate Monthly Cost for 30,000 Requests Source: https://dev.qweather.com/en/docs/finance/billing-and-payment Example calculation for a scenario with 30,000 weather API requests in a month, resulting in zero charges due to free tier pricing. ```text 30,000 requests x CNY 0 = CNY 0 ``` -------------------------------- ### Swift Indices Example Source: https://dev.qweather.com/en/docs/resource/indices-info Example of how to use the SPT (Sports) index in Swift. ```Swift let _ = Indices.SPT ``` -------------------------------- ### Get Real-Time Weather (Swift) Source: https://dev.qweather.com/en/docs/configuration/ios-sdk-config Fetches current weather data for a specified location using the QWeather SDK in Swift. Ensure the SDK is imported and initialized. ```swift import QWeatherSDK ... Task { do { let parameter = WeatherParameter(location: "101010100") let response = try await QWeather.instance.weatherNow(parameter) print(response) } catch QWeatherError.errorResponse(let error) { print(error) } catch { print(error) } } ``` -------------------------------- ### Fetch Grid Weather Real-time Data (Swift) Source: https://dev.qweather.com/en/docs/ios-sdk/weather/ios-grid-weather-now Use this Swift code to fetch current grid weather data. Ensure you have initialized the QWeather instance and handle potential errors. ```swift Task{ do { let parameter = GridWeatherParameter(longitude: 116.41, latitude: 39.92) let response = try await QWeather.instance .gridNow(parameter) print(response) } catch QWeatherError.errorResponse(let error) { print(error) } catch { print(error) } } ``` -------------------------------- ### JWT Header Example Source: https://dev.qweather.com/en/docs/configuration/authentication Example of the Header part of a JWT, specifying the signature algorithm and credential ID. ```json { "alg": "EdDSA", "kid": "ABCDE12345" } ``` -------------------------------- ### Complete JWT Example Source: https://dev.qweather.com/en/docs/configuration/authentication An example of a complete JWT, formed by concatenating the Base64URL-encoded Header, Payload, and Signature with dots. ```text eyJhbGciOiAiRWREU0EiLCJraWQiOiAiQUJDRDEyMzQifQ.eyJpc3MiOiJBQkNEMTIzNCIsImlhdCI6MTcwMzkxMjQwMCwiZXhwIjoxNzAzOTEyOTQwfQ.MEQCIFGLmpmAEwuhB74mR04JWg_odEau6KYHYLRXs8Bp_miIAiBMU5O13vnv9ieEBSK71v4UULMI4K5T9El6bCxBkW4BdA ```