我正在使用下面的代码来获取地址信息,并且正在获取整个地址。但是对于给定的美国城市和邮编,我只需要县即可。请帮助
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));
}
});
}
答案 0 :(得分:0)
请尝试下面的代码访问响应的县属性。 希望有帮助。
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"
}
]
}
}
}
]
}
]
}
}