【发布时间】:2010-02-28 05:55:59
【问题描述】:
我正在使用 google maps API 地理编码服务来获取位置的国家名称、邮政编码等。
JSON 响应:
{
"name": "1600 Amphitheatre Parkway, Mountain View, CA, USA",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [
{
"address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"AddressDetails": {
"Country": {
"CountryNameCode": "US",
"AdministrativeArea": {
"AdministrativeAreaName": "CA",
"SubAdministrativeArea": {
"SubAdministrativeAreaName": "Santa Clara",
"Locality": {
"LocalityName": "Mountain View",
"Thoroughfare": {
"ThoroughfareName": "1600 Amphitheatre Pkwy"
},
"PostalCode": {
"PostalCodeNumber": "94043"
}
}
}
}
},
"Accuracy": 8
},
"Point": {
"coordinates": [-122.083739, 37.423021, 0]
}
}
]
}
这就是问题所在 - 有时(尽管检查未定义)我收到一个国家未定义的错误。
var country = document.getElementById("id_country");
if(place.AddressDetails.Country.CountryNameCode != undefined){
country.value = place.AddressDetails.Country.CountryNameCode;
}
另外,我如何访问 PostalCodeNumber?
place.AddressDetails.AdministrativeArea.SubAdministrativeArea.PostalCode.PostalCodeNumber
【问题讨论】:
标签: javascript json google-maps geocoding