This was working before, now I am getting the error Undefined offset: 0
<?php
$add = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$dlocation = $add . $city . $state;
$address = $dlocation; // Google HQ
$prepAddr = str_replace(' ', '+', $address);
$geocode = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='; . $prepAddr . '&sensor=false');
$output = json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Default Page">
<meta name="author" content="Gary Ehrenfeld">
<link rel="icon" href="../favicon.ico">
<title></title>
<!-- Bootstrap core CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/glyphicons-filetypes.css" rel="stylesheet">
<link href="../css/map.css" rel="stylesheet">
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?&key=AIzaSyClbVA0qYlfviEN6Dtjxu9VyNbcoqJIh04"></script>
<script type="text/javascript">
var map;
var geocoder;
var centerChangedLast;
var reverseGeocodedLast;
var currentReverseGeocodeResponse;
var my_latitude = <?= $latitude ?>;
var my_longitude = <?= $longitude ?>;
function initialize() {
var latlng = new google.maps.LatLng(my_latitude, my_longitude);
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder = new google.maps.Geocoder();
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Your Location"
});
}
</script>
</head>
<body onload="initialize()">
<div align="center">
<div>
<?php
echo "<h4>" . $add . ", " . $city . ", " . $state . "
";
echo "Latitude:  " . $latitude . "</br>";
echo "Longitude:  " . $longitude . "</h4></br>";
?>
</div>
<div id="map" style="width:700px; height:800px">
<div id="map_canvas" style="width:100%; height:800px"></div>
</div>
<div>
<a class="btn btn-primary btn-lg" href="../index.html" role="button">Return</a>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
Any idea why?
Thanks