OK, I am trying to set up a page that a user can enter in an address and that information will then “generate” a call to the google maps API to make an iframe for display in another page.
If found the following online but it does not get any information
<?php
// First, setup the variables you will use on your <iframe> code
// Your Iframe will need a Width and Height set
// as well as the address you plan to Iframe
// Don't forget to get a Google Maps API key
$latitude = '';
$longitude = '';
$iframe_width = '400px';
$iframe_height = '400px';
$address = '12215 East Sprague Avenue, Spokane Valley, WA 99206';
echo 'Addres to find: ' . $address . '<br>';
$address = urlencode($address);
$key = "AIzaSyDwDLLJCtmZCJaquWBWlKecSy46i_5StGc";
$url = "http://maps.google.com/maps/geo?q=".$address."&output=json&key=".$key;
echo 'URL: ' . $url . '<br>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
// Comment out the line below if you receive an error on certain hosts that have security restrictions
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$geo_json = json_decode($data, true);
// Uncomment the line below to see the full output from the API request
// var_dump($geo_json);
// If the Json request was successful (status 200) proceed
if ($geo_json['Status']['code'] == '200') {
$latitude = $geo_json['Placemark'][0]['Point']['coordinates'][0];
$longitude = $geo_json['Placemark'][0]['Point']['coordinates'][1]; ?>
<iframe width="<?php echo $iframe_width; ?>" height="<?php echo $iframe_height; ?>" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="
http://maps.google.com/maps
?f=q
&source=s_q
&hl=en
&geocode=
&q=<?php echo $address; ?>
&aq=0
&ie=UTF8
&hq=
&hnear=<?php echo $address; ?>
&t=m
&ll=<?php echo $longitude; ?>,<?php echo $latitude; ?>
&z=12
&iwloc=
&output=embed"></iframe>
<?php
} else { echo "<p>No Address Available</p>";}
?>
Putting this on my site, I get the following information:
Addres to find: 12215 East Sprague Avenue, Spokane Valley, WA 99206
URL: http://maps.google.com/maps/geo?q=12215+East+Sprague+Avenue%2C+Spokane+Valley%2C+WA+99206&output=json&key=AIzaSyDwDLLJCtmZCJaquWBWlKecSy46i_5StGc
No Address Available
Any idea why the “No Address Available” comes back?
E