2013-11-21 27 views
0

我使用谷歌时区API来检索时区,我的代码是在谷歌时区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" 
} 

当我运行上面URL,我得到正确的输出

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

任何想法如何解决这个

回答

2

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

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

这就是它..谢谢 –

+0

谢谢。这帮助了我。 – solar411

相关问题