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 で非オブジェクトのプロパティを取得しようとしています
私のコードで間違っているのは何ですか? 誰か助けてくれませんか?
ありがとう。
役に立たない答え!