我正在使用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×tamp=1419283200&sensor=false
{
"status" : "INVALID_REQUEST"
}
当我运行上面的网址时,我得到正确的输出
{
"dstOffset" : 0,
"rawOffset" : -18000,
"status" : "OK",
"timeZoneId" : "America/New_York",
"timeZoneName" : "Eastern Standard Time"
}
任何想法如何解决这个问题
答案 0 :(得分:2)
您的$url
无效。试试这个:
$url = "https://maps.googleapis.com/maps/api/timezone/json?location=".$lat.",".$lng."×tamp=1419283200&sensor=false";