Procházet zdrojové kódy

changed UserController, LocationFactory,allpositions.blade,userdate.blade

Maksimus111 před 5 roky
rodič
revize
a58b2a2ebe

+ 8 - 6
app/Http/Controllers/UserController.php

@@ -20,7 +20,9 @@ class UserController extends Controller
     }
 
     public function showLast(User $id){
-        return $id->lastCoordinates;
+        $koordinata = $id->lastCoordinates;
+        //return $id->lastCoordinates;
+        return view('lastposition',compact('koordinata'));
     }
 
 
@@ -33,10 +35,10 @@ class UserController extends Controller
     
 
     public function userdata(User $id, $date) {
-      
-
-    return $id->locations()->whereDate('created_at', $date)->get();
-  
-   
+      //$dates = [];
+    $dates = $id->locations()->whereDate('created_at', $date)->get();
+    //return $id->locations()->whereDate('created_at', $date)->get();
+    return view('userdate',compact('dates'));
+   //return $dates[0]["lat"]." ".$dates[0]["lng"];
     }
 }

+ 4 - 4
database/factories/LocationFactory.php

@@ -6,15 +6,15 @@ use Faker\Generator as Faker;
 
 $factory->define(Location::class, function (Faker $faker) {
 
-    $lat = 36.16310;
-    $lng = 49.94950;
+    $lat = 49.94950;
+    $lng = 36.16310;
     $latArray = [];
     $lngArray = [];
     for ($i=0; $i<10; $i++){
         $latArray[] = $lat;
-        $lat += 0.13733;
+        $lat += 0.00715;
         $lngArray[] = $lng;
-        $lng += 0.00715;
+        $lng += 0.13733;
     }
     $time = Carbon::now()->subDays(rand(1, 10))->subHours(rand(8, -8));
 

+ 35 - 0
resources/views/allpositions.blade.php

@@ -4,9 +4,40 @@
 <head>
     <meta charset="utf-8">
     <title>Document</title>
+<style>
+      /* Always set the map height explicitly to define the size of the div
+       * element that contains the map. */
+      #map {
+        height: 100%;
+	
+      }
+      /* Optional: Makes the sample page fill the window. */
+      html, body {
+        height: 100%;
+        margin: 0;
+        padding: 0;
+      }
+    </style>
+
 </head>
 <body>
 
+	  
+    <div id="map"></div>
+    <script>
+      var map;
+      function initMap() {
+        map = new google.maps.Map(document.getElementById('map'), { /*
+          center: {lat: 36.84975, lng: 49.97095},*/
+          zoom: 15
+        });
+
+        
+      
+      }
+    </script>
+
+
     <ul>
       @foreach ($users as $user)
 
@@ -18,6 +49,10 @@
 
     @endforeach
     </ul>
+
+	
+<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB8gUrKIK6UryDcJOEZD9V3fxpdDk8s4Lo&callback=initMap"
+    async defer></script>
 </body>
 
    

+ 47 - 3
resources/views/userdate.blade.php

@@ -4,21 +4,65 @@
 <head>
     <meta charset="utf-8">
     <title>Document</title>
+
+<style>
+      /* Always set the map height explicitly to define the size of the div
+       * element that contains the map. */
+      #map {
+        height: 100%;
+	
+      }
+      /* Optional: Makes the sample page fill the window. */
+      html, body {
+        height: 100%;
+        margin: 0;
+        padding: 0;
+      }
+    </style>
 </head>
 <body>
+	
+
+<div id="map"></div>
+    <script>
+
+      var map;
+      function initMap() {
+
+        map = new google.maps.Map(document.getElementById('map'), { /*
+          center: {lat:{{ $dates  }} , lng:{{ $dates  }}  },*/
+          zoom: 15
+        });
+	
+	var marker = new Array();
+  @foreach ($dates as $data)
+
+        map.setCenter({lat:{{ $data->lat  }} , lng:{{ $data->lng  }}  });
+         marker = new google.maps.Marker({
+          map:map,
+          position:{lat:{{ $data->lat  }} , lng:{{ $data->lng  }}  }
+          
+        });
+
+       @endforeach
+      }
+    </script>
 
     <ul>
-      @foreach ($dates as $data)
+     
 
 
         <li>
 		
-        	{{ $data }}
+        	{{ $dates }}
         </li>
 
 
-    @endforeach
+   
     </ul>
+
+<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB8gUrKIK6UryDcJOEZD9V3fxpdDk8s4Lo&callback=initMap"
+    async defer></script>
 </body>