mardi 31 mai 2016

Why are the php variables not working with my Javascript/Laravel-5 Google Maps Code?

I'm working on a laravel-5 application which requires me to sync data from a database and display it on google maps. The problem that I'm encountering is that whenever I run the code, it gives me an error that says:

Trying to get property of non-object (View: C:\xampp\htdocs\appl\resources\views\getmap6.blade.php)

The code for my page is as follows:

<!DOCTYPE html>
<html>
<head>                  

<script src="http://ift.tt/1WuAt15"></script>
<script>

            function initialize() 
                {
                    var mapProp = {
                                    center:new google.maps.LatLng(51.508742,-0.120850),
                                    zoom:13,
                                    mapTypeId:google.maps.MapTypeId.ROADMAP
                                  };

                    var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
                    var infowindow = null;

                    <?php for($i=1; $i<3; $i++)
                            {
                                $offLinks = App\offerlink::find($i);
                    ?>            

                    var marker=new google.maps.Marker({
                                                position: new google.maps.LatLng(<?php echo $offLinks->lat; ?>,<?php echo $offLinks->lng; ?>),
                                                icon: 'http://ift.tt/1focNmg'
                                             });

                    marker.setMap(map);

                    infowindow = new google.maps.InfoWindow({
                                                                content: "<b>Name: </b>" + "<?php echo $offLinks->name; ?>" + "<br> <b>Address: </b>" + "<?php echo $offLinks->address; ?>",
                                                            });



                    infowindow.open(map,marker);

                                        google.maps.event.addListener(marker, 'click', function() {

                                                                                infowindow.setContent(marker);
                                                                                infowindow.open(map,this);
                                                                              });

                            <?php } ?>  


                    google.maps.event.addListener(marker, 'click', function() {

                                                                                infowindow.setContent(marker);
                                                                                infowindow.open(map,this);
                                                                              });       

                }

                google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>

</html>

This code works on a local server which syncs to a phpMyAdmin database. The other pages don't have any issues when trying to connect to the database. It is only this page that has the issue. I know that the problem lies in the following lines of the code because because without those lines, there are no errors:

position: new google.maps.LatLng(<?php echo $offLinks->lat; ?>,<?php echo $offLinks->lng; ?>),

and

content: "<b>Name: </b>" + "<?php echo $offLinks->name; ?>" + "<br> <b>Address: </b>" + "<?php echo $offLinks->address; ?>",

Clearly, there is something wrong in the way I'm trying to use the php variables. I believe this code was working fine a few days ago.

Thank you for your time and effort.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1PfcAbm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire