我有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 19Notice: Trying to get property of non-object in D:\Software\Installed\xampp\htdocs\Classified- website\lat-long.php on line 23
什麼是我的代碼錯了嗎?有人幫我嗎?
謝謝。
沒有幫助回答!
它看起來不像你的代碼有什麼問題。更多與網關:*「HTTP請求失敗!HTTP/1.0 504網關超時」* – hakre
那麼,@hakre所以需要做什麼來解決它? – Alex
您是否聯繫了網關的運營商並向他們報告了問題?因爲我會先問那裏,而不是我。我沒有爲你運行那個網關,你知道嗎? ;) – hakre