Reputation: 9
I've HTML form with 5 fields.
1) Address 2) city 3) state 4) country 5) postcode.
After input this field value it's show Google map.
Google map code:
<?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
}
?>
But after submit in process page it's show following error:
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
What is the wrong in my code? Is there anyone help me?
Thanks.
No helpful answered!
Upvotes: 0
Views: 1887
Reputation: 1
Try this:
$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)
);
Upvotes: -1
Reputation: 51411
From 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.
So, either you have a proxy server sitting between you and the internet, and it returned this error, or the Google Maps server(s) you're hitting are non-responsive and their reverse proxies / load balancers can't serve you the page in time.
Speak to your web hosting provider about any proxy server they might be using. As it looks like this is on your local PC, then chances are that your "web hosting provider" is either your IT department (business, school) or your ISP (home user). If they aren't using a proxy, then the problem probably isn't on your end and isn't under your control.
Upvotes: 2