合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
根据经纬度获取地区的时区信息。
返回1条记录。
承载协议 | HTTPS POST |
|---|---|
接口方向 | 开发者 -> 华为地图服务器 |
接口URL | https://siteapi.cloud.huawei.com/mapApi/v1/timezoneService/getTimezone?key=API KEY 说明
|
数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
Request Header
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
Authorization | 是 | String | 业务签名,用于认证鉴权,格式为:Bearer+空格+API Key。 示例:Bearer ABC/DFG+。 |
Content-Type | 是 | application/json | 请求消息的数据格式。 |
Request Body
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
location | 是 | 经纬度。 | |
timestamp | 是 | Long | 距离UTC 1970年1月1日0点0分0秒的秒数。 |
language | 否 | String(<=16) | 搜索结果的语种,语种取值请参见支持的语言列表。如果不传,返回地点的当地语言。 |
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" }
状态码为200时:
Response Header
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
Content-Type | 是 | application/json | 响应消息的数据格式。 |
Response Body
参数名称 | 参数类型 | 描述 |
|---|---|---|
returnCode | String | 返回码,具体请参见错误码。 |
returnDesc | String | 返回值描述。 |
dstOffset | int | 夏令时的偏移量,单位:秒。 如果给定的timestamp不在夏令时里,返回0。 |
rawOffset | int | 给定位置与UTC的偏移量(单位:秒)。 |
timeZoneId | String | 时区ID。 例如“ America / Los_Angeles”或“ Australia / Sydney” 这些ID由Unicode 公共区域数据存储库(CLDR)项目定义。 可以参见GitHub上的链接。 |
timeZoneName | String | 时区名称。比如太平洋夏令时。 |
状态码为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());
}
});
}
}