【发布时间】:2014-09-30 10:11:57
【问题描述】:
我想从这个 google api 数组中获取 Postcode [ "long_name" : "S35 1TZ",]
我正在使用这个 API
http://maps.googleapis.com/maps/api/geocode/json?address=(53.4624118,%20-1.4922259999999596)
使用
msg.results[0].address_components[6].long_name;
不工作
{
"results" : [
{
"address_components" : [
{
"long_name" : "7A",
"short_name" : "7A",
"types" : [ "street_number" ]
},
{
"long_name" : "Hollow Gate",
"short_name" : "Hollow Gate",
"types" : [ "route" ]
},
{
"long_name" : "Chapeltown",
"short_name" : "Chapeltown",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Sheffield",
"short_name" : "Sheffield",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Sheffield",
"short_name" : "Sheffield",
"types" : [ "postal_town" ]
},
{
"long_name" : "South Yorkshire",
"short_name" : "South York",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "United Kingdom",
"short_name" : "GB",
"types" : [ "country", "political" ]
},
{
"long_name" : "S35 1TZ",
"short_name" : "S35 1TZ",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "7A Hollow Gate, Sheffield, South Yorkshire S35 1TZ, UK",
"geometry" : {
"location" : {
"lat" : 53.4624118,
"lng" : -1.492226
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 53.4637607802915,
"lng" : -1.490877019708498
},
"southwest" : {
"lat" : 53.4610628197085,
"lng" : -1.493574980291502
}
}
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
【问题讨论】:
-
即使代码不正确,请注意
6应该是7。
标签: php arrays google-maps