【发布时间】:2018-05-20 06:25:14
【问题描述】:
有没有办法获得 ISO 3166-2 与 Bing Maps Locations API 组合的特定 PostalCode/CountryCode 代码?
例如:1210/AT => AT-9
【问题讨论】:
有没有办法获得 ISO 3166-2 与 Bing Maps Locations API 组合的特定 PostalCode/CountryCode 代码?
例如:1210/AT => AT-9
【问题讨论】:
使用 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 包可以轻松包含在您的项目中。
【讨论】: