What am I doing wrong? Please help.

<?php 
  
    include '../../Controller/dbconn.php';
   
  function map()
{
  $myID = isset($_GET['cid']) ? $_GET['cid'] : false;
  if (!$myID) return '';

  $db = con();

  $sql = "SELECT restaurant_addr FROM restaurants WHERE restaurant_id = $myID";
  $stmt = $db->prepare($sql);
  $stmt->execute(array());
  $row = $stmt->fetch(PDO::FETCH_ASSOC);


  $geocode = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($row['restaurant_addr']));
   
  $lat_long = get_object_vars(json_decode($geocode));
  
  $lat_long = $lat_long['results'][0]->geometry->location->lat . "," . $lat_long['results'][0]->geometry->location->lng;

  // YOU NEED TO RETURN A VALUE HERE
  return $lat_long;
}
?>

Open in new window


 <script>
      var map;
      function initialize() {
        <br />
<b>Notice</b>:  Undefined offset: 0 in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Undefined offset: 0 in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\XAMPP\htdocs\KaonTaBai2\Model\Customer\restaurantinfo.php</b> on line <b>22</b><br />
        var myLatlng = new google.maps.LatLng(,);
        mapOptions = {
          zoom: 8,
          center: myLatlng
        };
        map = new google.maps.Map(document.getElementById('map'), mapOptions),
        marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
        });
      }
    </script>

Open in new window


I cant seem to pass the value of $lat_long to  var myLatlng = new google.maps.LatLng(,);
HermesStudentAsked:
Who is Participating?
 
mohan singhWeb developerCommented:
Undefined offset:  that means your array packet content have more than exist content
so check your array packet OR array content which you used
0
 
mohan singhWeb developerCommented:
Undefined offset always occurred in array packets
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.