目录

Time Zone Search

Function

Obtains the time zone information about a place based on its longitude and latitude.

Restrictions

One record is returned.

Prototype

Protocol

HTTPS POST

Direction

Your server -> Map Kit server

URL

https://siteapi.cloud.huawei.com/mapApi/v1/timezoneService/getTimezone?key=API KEY

NOTE:
  1. For details about API KEY, please refer to Obtaining the API Key.
  2. You can use the API key in either of the following ways:

    2.1 Concatenating it into the URL: Call the URLEncoder.encode("Your API key", "UTF-8") method to encode the API key using encodeURI. For example, if the original API key is ABC/DFG+, the conversion result is ABC%2FDFG%2B.

    2.2 Placing it in the header: Refer to the Authorization field in Request Header. This way is recommended.

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Request Parameters

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

Coordinate

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.

Request Example

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"
}

Response Parameters

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.

Response Example

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"
}

Call Example

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());
            }
        });
    }
}