here-api - 当我们使用 Rest API 时如何获取给定地址的县信息
问题描述
我正在使用下面的代码来获取地址信息,并且我正在获取整个地址。但我只需要给定城市的县和美国的邮编。请帮忙
function getCounty()
{
$.ajax({
url: 'https://geocoder.api.here.com/6.2/geocode.json',
type: 'GET',
dataType: 'jsonp',
jsonp: 'jsoncallback',
data: {
city: 'Farmington',
postalcode: '48335',
country: 'usa',
app_id: '**************************',
app_code: '************************',
gen: '9'
},
success: function (data) {
alert(JSON.stringify(data));
}
});
}
解决方案
请尝试以下代码以访问响应的县属性。希望这有帮助。
alert(data.Response.View[0].Result[0].Location.Address.County);
请检查以下请求的完整 JSON 响应。
{
"Response": {
"MetaInfo": {
"Timestamp": "2019-01-09T07:08:18.912+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1,
"MatchLevel": "postalCode",
"MatchQuality": {
"City": 1,
"PostalCode": 1
},
"Location": {
"LocationId": "NT_9usvaftBv-o9T6WyVpnWRC",
"LocationType": "area",
"DisplayPosition": {
"Latitude": 42.47427,
"Longitude": -83.40889
},
"NavigationPosition": [
{
"Latitude": 42.47427,
"Longitude": -83.40889
}
],
"MapView": {
"TopLeft": {
"Latitude": 42.48732,
"Longitude": -83.4355
},
"BottomRight": {
"Latitude": 42.43954,
"Longitude": -83.37537
}
},
"Address": {
"Label": "48335, Farmington, MI, United States",
"Country": "USA",
"State": "MI",
"County": "Oakland",
"City": "Farmington",
"PostalCode": "48335",
"AdditionalData": [
{
"value": "United States",
"key": "CountryName"
},
{
"value": "Michigan",
"key": "StateName"
},
{
"value": "Oakland",
"key": "CountyName"
},
{
"value": "N",
"key": "PostalCodeType"
}
]
}
}
}
]
}
]
}
}
推荐阅读
- websphere - WebSphere Web App 上的后退按钮后文档过期
- google-sheets - 谷歌表格 - 拖动包含公式的 n 行
- python - JupyterHub 无法访问:在 http://8000 上运行
- powershell - 需要针对此脚本在 foreach 中合并多个变量的帮助
- java - 如何使用 Install4J 将 EULA 屏幕添加到我的 MacOS 单一包存档?
- angular - NgbModal - 打开子模态时将结果返回给父级
- swift - 在不知道具体类型的情况下实例化集合
- r - 了解一个简单的网络图
- c# - Offset 变量在这个算法中的重要性是什么?
- regex - 匹配多行正则表达式模式的逆