2012-12-16 66 views
0

我有5個字段的HTML表單。谷歌地圖網關超時與PHP

1)地址2)城市3)州4)國家5)郵政編碼。

輸入此字段值後,顯示Google地圖。

谷歌地圖代碼:

<?php 
$add = urlencode($_POST['address']); 
$city = urlencode($_POST['city']); 
$state = urlencode($_POST['state']); 
$country = urlencode($_POST['country']); 
$zip = $_POST['zip']; 

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode 
/json?address='.$add.',+'.$city.',+'.$state.',+'.$country.'&sensor=false'); 

$output= json_decode($geocode); //Store values in variable 

if($output->status == 'OK'){ // Check if address is available or not 
echo "<br/>"; 
echo "Latitude : ".$lat = $output->results[0]->geometry->location->lat; //Returns Latitude 
echo "<br/>"; 
echo "Longitude : ".$long = $output->results[0]->geometry->location->lng; // Returns Longitude 
?> 
<script type="text/javascript"> 
$(document).ready(function() { 
// Define the latitude and longitude positions 
var latitude = parseFloat("<?php echo $lat; ?>"); // Latitude get from above variable 
var longitude = parseFloat("<?php echo $long; ?>"); // Longitude from same 
var latlngPos = new google.maps.LatLng(latitude, longitude); 
// Set up options for the Google map 
var myOptions = { 
zoom: 10, 
center: latlngPos, 
mapTypeId: google.maps.MapTypeId.ROADMAP, 
zoomControlOptions: true, 
zoomControlOptions: { 
style: google.maps.ZoomControlStyle.LARGE 
} 
}; 
// Define the map 
map = new google.maps.Map(document.getElementById("map"), myOptions); 
// Add the marker 
var marker = new google.maps.Marker({ 
position: latlngPos, 
map: map, 
title: "test" 
}); 
}); 
</script> 
<div id="map" style="width:450px;height:350px; margin-top:10px;"></div> // Div in which 
Google Map will show 
<?php 
} 
?> 

但在提交進程頁之後它的顯示以下錯誤:

Warning: file_get_contents(http://maps.google.com/maps/api/geocode
/json?address=,+Dhaka,+,+Bangladesh&sensor=false): failed to open stream: HTTP request failed! HTTP/1.0 504 Gateway Timeout in D:\Software\Installed\xampp\htdocs\Classified-website \lat-long.php on line 19

Notice: Trying to get property of non-object in D:\Software\Installed\xampp\htdocs\Classified- website\lat-long.php on line 23

什麼是我的代碼錯了嗎?有人幫我嗎?
謝謝。

沒有幫助回答!

+2

它看起來不像你的代碼有什麼問題。更多與網關:*「HTTP請求失敗!HTTP/1.0 504網關超時」* – hakre

+0

那麼,@hakre所以需要做什麼來解決它? – Alex

+0

您是否聯繫了網關的運營商並向他們報告了問題?因爲我會先問那裏,而不是我。我沒有爲你運行那個網關,你知道嗎? ;) – hakre

回答

2

Wikipedia's article on HTTP status codes

504 Gateway Timeout

The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.

所以,要麼你有你和互聯網之間的代理服務器坐着,它返回這個錯誤,或者你打的谷歌地圖的服務器(S)的非響應和他們的反向代理/負載平衡器不能及時爲您提供頁面。

與您的虛擬主機提供商談論他們可能使用的任何代理服務器。由於它看起來像在您的本地PC上,因此您的「虛擬主機提供商」可能是您的IT部門(商業,學校)或您的ISP(家庭用戶)。如果他們沒有使用代理服務器,那麼問題可能不在您的盡頭,並且不在您的控制之下。