你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

迁移必应地图“查找时区”API

本文介绍了如何从必应地图查找时区 API 迁移到 Azure Maps 通过坐标获取时区 API。 Azure Maps“通过坐标获取时区”API 返回指定纬度-经度对的当前、历史和将来的时区信息,以及给定位置的日落和日出时间。

先决条件

显著差异

  • 必应地图“查找时区”API 支持将坐标和位置地名、行政区域和国家/地区名称作为位置输入。 Azure Maps“通过坐标获取时区”API 仅支持坐标。 若要获取位置地名、行政区域和国家/地区名称的坐标,可以使用 Azure Maps 获取地理编码 API。
  • 必应地图“查找时区”API 同时支持 XML 和 JSON 响应格式,Azure Maps“通过坐标获取时区”API 仅支持 JSON。
  • 必应地图“查找时区”API 不提供给定时区的日出和日落值,而 Azure Maps“通过坐标获取时区”API 提供。
  • 与必应地图企业版不同,Azure Maps 是一项支持指定地理范围的全局服务,可用于将数据驻留限制为欧洲 (EU) 或美国 (US) 地理区域(地区)。 所有请求(包括输入数据)都专门在指定的地理区域进行处理。 有关详细信息,请参阅 Azure Maps 服务地理范围

安全性和身份验证

必应地图企业版仅支持 API 密钥身份验证。 Azure Maps 支持通过多种方式对 API 调用进行身份验证,例如订阅密钥Microsoft Entra ID共享访问签名 (SAS) 令牌。 有关 Azure Maps 中的安全性和身份验证的详细信息,请参阅向 Azure Maps 进行身份验证和 Azure Maps“通过坐标获取时区”文档中的“安全”部分

请求参数

下表列出了必应地图“查找时区”请求参数和 Azure Maps 等效参数:

必应地图参数 必应地图参数别名 Azure Maps 参数 Azure Maps 中必需 Azure Maps 数据类型 说明
dateTime dt timeStamp False 字符串(日期时间) 或者,使用别名“stamp”或“s”。 参考时间,如果省略,该 API 将使用为请求提供服务的计算机时间。
IncludeDstRules transitionsFrom False 字符串(日期时间) 从中请求夏令时 (DST) 转换的开始日期,仅当 "options" = all 或 "options" = transitions 时适用。 有关详细信息,请参阅 options(时区选项)参数。  
output o format True JSONFormat 此 Azure Maps API 仅支持 JSON 格式。
point query True 数字 请求其时区信息的点的坐标。 此参数是一个坐标列表,包含一对坐标值 (纬度, 经度)。 直接调用此终结点时,坐标作为包含逗号分隔坐标的单个字符串传入。
查询 q 不支持 不支持 不支持 仅支持请求了其时区信息的点的坐标。 不支持位置类型,例如地址、地点、邮政编码等等。 若要获取位置地名、行政区域和国家/地区名称的坐标,可以使用 Azure Maps“获取地理编码”API。

有关详细信息,请参阅 Azure Maps“通过坐标获取时区”URI 参数

请求示例

必应地图“查找时区”API 请求:

https://dev.virtualearth.net/REST/v1/timezone/37.7800,-122.4201?key=%7bBingMapsKey%7d

Azure Maps“通过坐标获取时区”API 请求:

https://atlas.microsoft.com/timezone/byCoordinates/json?api-version=1.0&query=37.7800,-122.4201&subscription-key={Your-Azure-Maps-Subscription-key}

响应字段

下表列出了运行必应地图“查找时区”API 和 Azure Maps 等效请求时,HTTP 响应中可能出现的字段:

必应地图响应字段 Azure Maps 响应字段
缩写 (JSON)
缩写 (XML)
ReferenceTime(标记)
convertedTime (JSON)
ConvertedTime (XML)
ReferenceTime (WallTime)
dstRule (JSON)
DSTRule (XML)
TimeTransitions
genericName (JSON)
GenericName (XML)
TimezoneNames
ianaTimeZoneId (JSON)
IANATimeZoneID (XML)
ID
utcOffset (JSON)
UTCOffset (XML)
ReferenceTime (StandardOffset)
windowsTimeZoneID (JSON)
WindowsTimeZoneID (XML)
不支持。 使用 Azure Maps“获取时区枚举”Windows API 转换为 Windows 时区。

有关 Azure Maps“通过坐标获取时区”响应字段的详细信息,请参阅响应定义

响应示例

以下 JSON 示例显示了执行必应地图的“查找时区”API 请求时,HTTP 响应正文中返回的内容:

{
    "authenticationResultCode": "ValidCredentials",
    "brandLogoUri": "https://dev.virtualearth.net/Branding/logo_powered_by.png",
    "copyright": "Copyright © 2024 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
    "resourceSets": [
        {
            "estimatedTotal": 1,
            "resources": [
                {
                    "__type": "RESTTimeZone:http://schemas.microsoft.com/search/local/ws/rest/v1",
                    "timeZone": {
                        "genericName": "Pacific Standard Time",
                        "abbreviation": "PST",
                        "ianaTimeZoneId": "America/Los_Angeles",
                        "windowsTimeZoneId": "Pacific Standard Time",
                        "utcOffset": "-8:00",
                        "convertedTime": {
                            "localTime": "2024-02-11T14:21:58",
                            "utcOffsetWithDst": "-8:00",
                            "timeZoneDisplayName": "Pacific Standard Time",
                            "timeZoneDisplayAbbr": "PST"
                        }
                    }
                }
            ]
        }
    ],
    "statusCode": 200,
    "statusDescription": "OK",
    "traceId": "f02637665942c8cb21c8414bd03224aa|MWH0032BEF|0.0.0.1"
}

以下示例显示了执行 Azure Maps“通过坐标获取时区”API 请求时 HTTP 响应正文中返回的内容:

{
    "Version": "2023d",
    "ReferenceUtcTimestamp": "2024-02-11T22:32:29.4282815Z",
    "TimeZones": [
        {
            "Id": "America/Los_Angeles",
            "Aliases": [
                "US/Pacific"
            ],
            "Countries": [
                {
                    "Name": "United States",
                    "Code": "US"
                }
            ],
            "Names": {
                "ISO6391LanguageCode": "en",
                "Generic": "Pacific Time",
                "Standard": "Pacific Standard Time",
                "Daylight": "Pacific Daylight Time"
            },
            "ReferenceTime": {
                "Tag": "PST",
                "StandardOffset": "-08:00:00",
                "DaylightSavings": "00:00:00",
                "WallTime": "2024-02-11T14:32:29.4282815-08:00",
                "PosixTzValidYear": 2024,
                "PosixTz": "PST+8PDT,M3.2.0,M11.1.0",
                "Sunrise": "2024-02-11T07:04:33.6950704-08:00",
                "Sunset": "2024-02-11T17:43:15.3679015-08:00"
            },
            "RepresentativePoint": {
                "Latitude": 34.05222222222222,
                "Longitude": -118.24277777777777
            },
            "TimeTransitions": [
                {
                    "Tag": "PST",
                    "StandardOffset": "-08:00:00",
                    "DaylightSavings": "00:00:00",
                    "UtcStart": "2023-11-05T09:00:00Z",
                    "UtcEnd": "2024-03-10T10:00:00Z"
                },
                {
                    "Tag": "PDT",
                    "StandardOffset": "-08:00:00",
                    "DaylightSavings": "01:00:00",
                    "UtcStart": "2024-03-10T10:00:00Z",
                    "UtcEnd": "2024-11-03T09:00:00Z"
                },
                {
                    "Tag": "PST",
                    "StandardOffset": "-08:00:00",
                    "DaylightSavings": "00:00:00",
                    "UtcStart": "2024-11-03T09:00:00Z",
                    "UtcEnd": "2025-03-09T10:00:00Z"
                }
            ]
        }
    ]
}

事务使用情况

与必应地图企业版“查找时区”API 类似,Azure Maps“通过坐标获取时区”API 为每个 API 请求记录一个计费事务。 有关 Azure Maps 事务的详细信息,请参阅了解 Azure Maps 事务

其他信息

更多 Azure Maps 时区 API

支持