dimanche 30 juillet 2017

How to pass PHP array to vue js file from blade format html

i'm working on laravel framework using google map api with vue.js and facebook's graph api with php. i need to get an array of longitude and latitude of that places coming from facebook's graph api to show them on map using google map api. the array of places is coming from a function of php class and graph is forming up in vue.js file, and here i'm facing a problem that how can i get that php array in vue.js so that i would be able to show them(places) on map.

var app = new Vue({

        el: '#app',
        mounted(){
                var self = this;
                this.$on('google.maps:init', function(){
                self.createMap()
        });
        },
  data:{
    lat : ''
  },
        methods: {
                 facebookCheckins : function(){
         var map= new google.maps.Map(document.querySelector('#map'),{
         center: {lat: 35, lng: -85},
          zoom:12
        });
        for (var i = lat.length - 1; i >= 0; i--) {
                
                            var marker = new google.maps.Marker({
                              position: {lat: lat[i]['latitude'] , lng: lat[i]['longitude']},
                              map: map,
                              title:place['name']
                        });
        }
     }
        }
});
<div id="app">
        <h5><?php echo $lat ?></h5>
        <form @submit.prevent="facebookCheckins">
  <!-- **here i'm passing that array in js file** -->
                <input type="hidden" id="lat" v-model="" name="lat_lng">
                <button type="submit">Locate</button>
        </form>
        
        <div id="map"></div>
        </div>
         <script src="http://ift.tt/2agbZVE"></script>
        <script src=""></script>

        <script src="http://ift.tt/2wcJAJ1" async defer></script>

And in Controller // making object of class where facebook graph api code is written $obj=new App\Place(); $results=$obj->searchPlaces(31.55,74.375); $resultsize=count($results); for ($i=0; $i placesInfo($results[$i]['id']); $latitude=$place['location']['latitude']; $longitude=$place['location']['longitude']; $lat_lng[$i]= array('latitude' =>$latitude ,'longitude'=>$longitude );
$lat=json_encode($lat_lng); }

return view('facebook_place_search')->withLat($lat);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire