Google时区API始终返回错误状态

时间:2013-11-21 10:08:55

标签: php google-maps-api-3 timezone

我正在使用Google时区API检索时区,我的代码是

$lat = round($location['lat'], 2);
$lng = round($location['lng'], 2);

$url = "https://maps.googleapis.com/maps/api/timezone/jsonlocation=".$lat.",".$lng."&timestamp=1419283200&sensor=false";
$url = str_replace(' ','',$url);
$json_timezone = file_get_contents($url);
echo $url;
echo '<pre>';print_r($json_timezone);

输出

https://maps.googleapis.com/maps/api/timezone/json?location=39.29,-76.64&timestamp=1419283200&sensor=false

{
   "status" : "INVALID_REQUEST"
}

当我运行上面的网址时,我得到正确的输出

{
   "dstOffset" : 0,
   "rawOffset" : -18000,
   "status" : "OK",
   "timeZoneId" : "America/New_York",
   "timeZoneName" : "Eastern Standard Time"
}

任何想法如何解决这个问题

1 个答案:

答案 0 :(得分:2)

您的$url无效。试试这个:

$url = "https://maps.googleapis.com/maps/api/timezone/json?location=".$lat.",".$lng."&timestamp=1419283200&sensor=false";