Google maps 使用PHP的Google地图网关超时

Google maps 使用PHP的Google地图网关超时,google-maps,php,Google Maps,Php,我有5个字段的HTML表单 1) 地址2)城市3)州4)国家5)邮政编码 输入此字段值后,显示谷歌地图 谷歌地图代码: <?php $add = urlencode($_POST['address']); $city = urlencode($_POST['city']); $state = urlencode($_POST['state']); $country = urlencode($_POST['country']); $zip = $_POST['zip']; $geocod

我有5个字段的HTML表单

1) 地址2)城市3)州4)国家5)邮政编码

输入此字段值后,显示谷歌地图

谷歌地图代码:

<?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
}
?>

$(文档).ready(函数(){
//定义纬度和经度位置
var latitude=parseFloat(“”;//从上述变量获取纬度
var longitude=parseFloat(“”;//来自同一位置的经度
var latlngPos=new google.maps.LatLng(纬度、经度);
//为谷歌地图设置选项
变量myOptions={
缩放:10,
中心:latlngPos,
mapTypeId:google.maps.mapTypeId.ROADMAP,
ZoomControl选项:对,
ZoomControl选项:{
样式:google.maps.ZoomControlStyle.LARGE
}
};
//定义地图
map=新的google.maps.map(document.getElementById(“map”),myOptions);
//添加标记
var marker=new google.maps.marker({
职位:latlngPos,
地图:地图,
标题:“测试”
});
});
//其中的Div
谷歌地图将显示
但在进程中提交页面后,会显示以下错误:

警告:文件\u获取\u内容(http://maps.google.com/maps/api/geocode
/json?地址=,+Dhaka,+,+Bangladesh&sensor=false):无法打开流:HTTP请求失败! HTTP/1.0 504网关超时在D:\Software\Installed\xampp\htdocs\Classified网站中 \第19行的lat-long.php

注意:尝试获取D:\Software\Installed\xampp\htdocs\Classified中非对象的属性- 第23行的网站\lat-long.php

我的代码有什么问题?有人帮我吗?
谢谢

没有人回答来自:

504网关超时

服务器充当网关或代理,未收到来自上游服务器的及时响应

因此,要么你和互联网之间有一个代理服务器,它返回了这个错误,要么你正在访问的谷歌地图服务器没有响应,并且他们的反向代理/负载平衡器不能及时为你提供页面

向您的web托管提供商咨询他们可能使用的任何代理服务器。由于它看起来像是在你的本地PC上,那么你的“网络主机提供商”可能是你的it部门(商业、学校)或ISP(家庭用户)。如果他们不使用代理,那么问题可能不在您这边,也不在您的控制范围内。

尝试以下方法:

        $arrContextOptions=array(
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
            ),
        ); 

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

您的代码似乎没有任何问题。关于网关的更多信息:“HTTP请求失败!HTTP/1.0 504网关超时”@hakre那么需要做些什么来修复它?您是否联系了网关的操作员并向他们报告了问题?因为我会先问,不是我。你知道,我不是在为你管理门户在php中选中“允许url打开”或“关闭”。ini@Alex:否,您正在使用
maps.google.com
。最后一行似乎已从代码块中转义。用四个空格缩进代码以创建代码块。