2012-12-16 69 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(家庭用户)。如果他们没有使用代理服务器,那么问题可能不在您的尽头,并且不在您的控制之下。