Protocol | HTTPS POST |
|---|---|
Direction | Your server -> Map Kit server |
URL | https://siteapi.cloud.huawei.com/mapApi/v1/timezoneService/getTimezone?key=API KEY NOTE:
|
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Request Header
Parameter | Mandatory | Type | Description |
|---|---|---|---|
Authorization | Yes | String | Service signature, which is used for authentication. The value is in Bearer+Space+API key format. Example: Bearer ABC/DFG+ |
Content-Type | Yes | application/json | Data format of a request. |
Request Body
Parameter | Mandatory | Type | Description |
|---|---|---|---|
location | Yes | Longitude and latitude. | |
timestamp | Yes | Long | Number of seconds between the current time and 00:00:00 on January 1, 1970 (UTC). |
language | No | String(<=16) | Language in which search results are displayed. For details, please refer to Supported Languages. If this parameter is not passed, the local language will be used. |
POST https://siteapi.cloud.huawei.com/mapApi/v1/timezoneService/getTimezone?key=API KEY HTTP/1.1 Content-Type: application/json Accept: application/json { "location": { "lng": 30.23235, "lat": 12.242585 }, "timestamp": 1577435043, "language": "en" }
When the status code is 200:
Response Header
Parameter | Mandatory | Type | Description |
|---|---|---|---|
Content-Type | Yes | application/json | Data format of a response. |
Response Body
Parameter | Type | Description |
|---|---|---|
returnCode | String | Result code. For details, please refer to Result Codes. |
returnDesc | String | Result description. |
dstOffset | int | DST offset, in seconds. If the specified timestamp is out of the DST, 0 will be returned. |
rawOffset | int | Time zone offset of a specified place from UTC, in seconds. |
timeZoneId | String | Time zone ID. For example, the value can be America / Los_Angeles or Australia / Sydney. The time zone IDs are defined in Unicode CLDR Project. For details, click here to visit GitHub. |
timeZoneName | String | Time zone name, for example, PDT. |
When the status code is 200:
HTTP/1.1 200 OK
Content-type: application/json
{
"returnCode": "0",
"timeZoneName": "Central African Time",
"rawOffset": 7200,
"timeZoneId": "Africa/Khartoum",
"dstOffset": 0,
"returnDesc": "OK"
} public class TimeZoneService {
public static final String ROOT_URL = "https://siteapi.cloud.huawei.com/mapApi/v1/timezoneService/getTimezone";
public static final String connection = "?key=";
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static void timeZone(String apiKey) throws UnsupportedEncodingException {
JSONObject json = new JSONObject();
JSONObject location = new JSONObject();
try {
location.put("lng", 30.23235);
location.put("lat", 12.242585);
json.put("location", location);
json.put("timestamp",1577435043);
} catch (JSONException e) {
Log.e("error", e.getMessage());
}
RequestBody body = RequestBody.create(JSON, String.valueOf(json));
OkHttpClient client = new OkHttpClient();
Request request =
new Request.Builder().url(ROOT_URL + connection + URLEncoder.encode(apiKey, "UTF-8"))
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TimeZone", e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d("TimeZone", response.body().string());
}
});
}
}