如何檢查對象中是否存在鄰域值?檢查對象中是否存在值
{
"results" : [
{
"address_components" : [
{
"long_name" : "2900",
"short_name" : "2900",
"types" : [ "street_number" ]
},
{
"long_name" : "Ranch Road 620 North",
"short_name" : "Ranch Rd 620 N",
"types" : [ "route" ]
},
{
"long_name" : "Villas On Travis",
"short_name" : "Villas On Travis",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Austin",
"short_name" : "Austin",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Travis County",
"short_name" : "Travis County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Texas",
"short_name" : "TX",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "78734",
"short_name" : "78734",
"types" : [ "postal_code" ]
},
{
"long_name" : "2209",
"short_name" : "2209",
"types" : [ "postal_code_suffix" ]
}
]
}
]
}
我已經試過
if ($jsonarray->results[0]->address_components[2]->types == 'neighborhood') {
$neighborhood = $jsonarray->results[0]->address_components[2]->long_name;
}
Anywhere的對象中的,或者在一個特定的地方? –
類型仍然是一個數組,所以你不需要說類型[0] – Rob85
只有一個地方:https://maps.googleapis.com/maps/api/geocode/json?latlng=30.560030000000,-97.691430000000 – santa