0

5 つのフィールドを持つ HTML フォームがあります。

1) 住所 2) 都市 3) 州 4) 国 5) 郵便番号。

このフィールド値を入力すると、Google マップが表示されます。

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

しかし、プロセスページで送信した後、次のエラーが表示されます:

警告: file_get_contents(http://maps.google.com/maps/api/geocode
/json?address=,+Dhaka,+,+Bangladesh&sensor=false): ストリームを開くことができませんでした: HTTP リクエストが失敗しました! HTTP/1.0 504 Gateway Timeout in D:\Software\Installed\xampp\htdocs\Classified-website \lat-long.php 行 19

注意: 23 行目の D:\Software\Installed\xampp\htdocs\Classified-website\lat-long.php で非オブジェクトのプロパティを取得しようとしています

私のコードで間違っているのは何ですか? 誰か助けてくれませんか?
ありがとう。

役に立たない答え!

4

2 に答える 2

2

HTTPステータスコードに関するウィキペディアの記事から:

504ゲートウェイのタイムアウト

サーバーはゲートウェイまたはプロキシとして機能しており、アップストリーム サーバーからタイムリーな応答を受け取りませんでした。

つまり、あなたとインターネットの間にプロキシ サーバーがあり、このエラーが返されたか、アクセスしている Google マップ サーバーが応答せず、リバース プロキシ/ロード バランサーがサービスを提供できないかのいずれかです。時間内のページ。

使用している可能性のあるプロキシ サーバーについて、Web ホスティング プロバイダーに相談してください。これはローカル PC にあるように見えるため、「Web ホスティング プロバイダー」は IT 部門 (企業、学校) または ISP (ホーム ユーザー) である可能性があります。彼らがプロキシを使用していない場合、問題はおそらくあなたの側にあるのではなく、あなたの管理下にありません.

于 2012-12-16T18:41:10.510 に答える