【发布时间】:2016-12-08 08:32:48
【问题描述】:
我正在使用 google Geocode api 从我发送的自定义语言环境中获取坐标和国家/地区。
我从中得到的回应是
{
"results" : [
{
"address_components" : [
{
"long_name" : "13",
"short_name" : "13",
"types" : [ "street_number" ]
},
{
"long_name" : "Vernon Park",
"short_name" : "Vernon Park",
"types" : [ "route" ]
},
{
"long_name" : "Toa Payoh",
"short_name" : "Toa Payoh",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Singapore",
"short_name" : "Singapore",
"types" : [ "locality", "political" ]
},
{
"long_name" : "367835",
"short_name" : "367835",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "13 Vernon Park, Singapore 367835",
"geometry" : {
"location" : {
"lat" : 1.340062,
"lng" : 103.880577
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 1.341410980291502,
"lng" : 103.8819259802915
},
"southwest" : {
"lat" : 1.338713019708498,
"lng" : 103.8792280197085
}
}
},
"place_id" : "ChIJbXRmsZAX2jERv_hlVeqBXtM",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
我为从响应中获取国家/地区而编写的 php 代码是,
foreach($response['results'][0]['address_components'] as $addressComponet){
if(in_array('country', $addressComponet['types'])) {
if($addressComponet['short_name'] != $addressComponet['long_name'])
$country = $addressComponet['long_name'];
else
$country = $addressComponet['long_name'];
}
}
$geometry = $response['results'][0]['geometry'];
$longitude = $geometry['location']['lng'];
$latitude = $geometry['location']['lat'];
$array = array(
'latitude' => $latitude,
'longitude' => $longitude,
'location_type' => $geometry['location_type'],
'country' => $country
);
其中$response 包含 curl_exec 响应。直到昨天,这似乎一直运行良好。但是,从今天开始,我没有在数组中获取国家/地区字符串。 api 响应有什么我不知道的变化吗?
【问题讨论】:
-
我不会把它联系起来,因为变化发生在一夜之间。
-
可能发布了新版本的 API
-
那么我必须做些什么才能使其与以前保存的接收 ZERO_RESULTS 或没有国家名称的语言环境兼容?
标签: php google-maps google-maps-api-3