【问题标题】:Get ISO 3166-2 Code from Bing Maps Locations API从 Bing 地图位置 API 获取 ISO 3166-2 代码
【发布时间】:2018-05-20 06:25:14
【问题描述】:

有没有办法获得 ISO 3166-2 与 Bing Maps Locations API 组合的特定 PostalCode/CountryCode 代码?

例如:1210/AT => AT-9

【问题讨论】:

    标签: bing-maps iso-3166


    【解决方案1】:

    使用 Bing 地图 REST 位置 API 并对您的查询(邮政、国家/地区...)进行地理编码。作为请求的一部分,添加&incl=ciso2,它将返回国家/地区的 ISO2 代码值。例如:

    https://dev.virtualearth.net/REST/v1/Locations?q=1210%2C%20AT&incl=ciso2&key=YOUR_Bing_Maps_Key

    将返回以下内容:

    {
    "authenticationResultCode": "ValidCredentials",
    "brandLogoUri": "http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
    "copyright": "Copyright © 2017 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": "Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
            "bbox": [48.237850189209, 16.3536491394043, 48.3225288391113, 16.4731197357178],
            "name": "1210, Austria",
            "point": {
                "type": "Point",
                "coordinates": [48.2801895141602, 16.4104042053223]
            },
            "address": {
                "adminDistrict": "Vienna",
                "adminDistrict2": "Vienna",
                "countryRegion": "Austria",
                "formattedAddress": "1210, Austria",
                "locality": "Vienna",
                "postalCode": "1210",
                "countryRegionIso2": "AT"
            },
            "confidence": "High",
            "entityType": "Postcode1",
            "geocodePoints": [{
                "type": "Point",
                "coordinates": [48.2801895141602, 16.4104042053223],
                "calculationMethod": "Rooftop",
                "usageTypes": ["Display"]
            }],
            "matchCodes": ["Good"]
        }]
    }],
    "statusCode": 200,
    "statusDescription": "OK",
    "traceId": "cb93431f2caa4f9fb2fcdbaa0ae80b74|CO30324109|7.7.0.0|"
    }
    

    注意在响应的地址属性中有"countryRegionIso2": "AT"

    可在此处找到有关 Bing 地图 REST 位置 API 的文档:https://msdn.microsoft.com/en-US/library/ff701711.aspx

    这里有一个最佳实践指南:https://msdn.microsoft.com/en-us/library/dn894107.aspx

    如果使用 .NET,您可能需要使用 Bing Maps REST .NET 工具包:https://github.com/Microsoft/BingMapsRESTToolkit 它使在 .NET 中使用 REST 服务变得非常容易,并且还有一个 NuGet 包可以轻松包含在您的项目中。

    【讨论】:

    • 感谢您的回答。但我不需要国家的 ISO2 代码。我需要 ISO 3166-2 代码(细分)(参见维基百科链接)。
    • 细分ISO2代码在平台中不可用,也没有计划添加。
    猜你喜欢
    • 2018-05-20
    • 2017-07-22
    • 2015-05-01
    • 2014-08-29
    • 2021-06-21
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    相关资源
    最近更新 更多