2016-08-23 3 views
0

Ich hole Werte aus der Datenbank und zeigt sie in einer Tabelle mit PHP Laravel. Breitengrad-Längengradwert wird abgerufen und in meiner Tabelle angezeigt. Da es eine andere Spaltenadresse gibt, muss ich in dieser Spalte die Adresse anzeigen, indem ich den entsprechenden Lat-Long-Wert aus der Datenbank umwandle. Kann jemand sagen, wie ich den Code dafür schreiben kann?Wie schreibe ich PHP-Code, um Breitengrad Längengrad zu Adresse in Laravel zu konvertieren 5.2

meine Sicht Klinge gibt unter

@extends('app') 

@section('content') 
    </br></br></br></br></br></br></br></br> 
    <div class="templatemo-content-wrapper"> 
     <div class="templatemo-content"> 
      <ol class="breadcrumb"> 
       <li><a href="{{ url("/") }}"><font color="green">Home</font></a></li> 
       <li class="active">Vehicle Report</li> 
      </ol> 
      <h1>Vehicle Report</h1> 

      <p></p> 

      <div class="row"> 
       <div class="col-md-12"> 
        <div class="table-responsive"> 

         <table id="example" class="table table-striped table-hover table-bordered"> 
          <thead> 
          <tr> 
           <th>Date</th> 
           <th>Time</th> 
           <th>Status</th> 
           <th>Lat/Long</th> 

           <th>Speed</th> 
           <th>Altitude</th> 
           <th>Odometer</th> 
           <th>Fuel</th> 
           <th>Address</th> 
          </tr> 
          </thead> 
          <tbody> 
          @foreach($devices as $device) 
           <tr> 

            <td>{{ date('Y/m/d H:i:s',($device->timestamp)) }}</td> 
            <td>{{ date('H:i:s',($device->timestamp)) }}</td> 
            <td>{{--}}{{ $device->statusCode }}--}} 
             @if($device->statusCode == '61715') 
              Stop 
             @elseif($device->statusCode=='62465') 
              Ignition_On 
              @elseif($device->statusCode=='61713') 
              Start 
             @elseif($device->statusCode=='61714') 
              InMotion 
             @elseif($device->statusCode=='62467') 
              Ignition_Off 

              @else 

              Speeding 
             @endif 

            </td> 
            <td>{{ round($device->latitude,5).'/'.round($device->longitude,5) }}</td> 

            <td>{{ $device->speed }}</td> 
            <td>{{ round($device->altitude) }}</td> 
            <td>{{ round($device->odometer) }}</td> 
            <td>{{ ($device->fuelLevel*100).'%' }}</td> 
            <td>{{ ?????????? }}</td> 


           </tr> 
          @endforeach 
          </tbody> 
         </table> 

        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
    </br> 





    </br></br></br></br> 

Controller-Seite ist

class ReportController extends Controller 
{ 
    public $type = 'Device'; 


    public function getAdd() 
    { 
     $vehicles = DB::table('device')->get(); 
     return view('reports.vehicleDetail')->with('vehicles', $vehicles); 
    } 


    public function get(Request $request) 
    { 

     $account = Account::select('accountID')->where('accountID','=','gts')->get(); 


     foreach ($account as $acc) { 
      $abc = $acc->accountID; 
     } 





     try { 
      $device_id = $request['deviceID']; 
      $from = strtotime($request['Fdate']); 
      $to = strtotime($request['Tdate']); 


      $devices=DB::table('device as b') 
       ->join('eventdata as a', 'a.deviceID', '=', 'b.deviceID') 
       ->where('a.deviceID', '=', $device_id) 
       ->where('a.accountID', '=', $abc) 
       ->where('a.creationTime', '>=', $from) 
       ->where('a.creationTime', '<=', $to) 
       ->select('a.accountID', 'a.deviceID', 'b.description', 'a.timestamp','a.statusCode', 
        'a.latitude', 'a.longitude', 'a.speedKPH as speed', 'a.heading', 'a.altitude', 'a.address', 'a.distanceKM as distance', 'a.odometerKM as odometer', 'a.IbatVolts', 'a.EbatVolts', 'a.ITempr', 'a.fuelLevel', 'a.inputState', 'a.IgnRuntime', 'GPSFixType', 'a.GPSPDOP', 'a.isTollRoad')->get(); 




//   $devices = DB::table('eventdata')->get(); 
      return view('reports.vehicleReport')->with('devices', $devices); 




     } catch (ModelNotFoundException $err) { 
      //Show error page 
     } 

    } 




} 

Vielen Dank im Voraus.

Antwort

0

Sie müssen Reverese Geocoding verwenden. Google Maps API wäre die beste Wahl.

<?php 
    if(isset($_POST['latitude'])){ 
    $lat=$_POST['latitude']; 
    $long=$_POST['longitude']; 
    $address=file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&key=YOUR_API_KEY"); 
    $json_data=json_decode($address); 
    $full_address=$json_data->results[0]->formatted_address; 
    } 
?> 
+0

können wir diesen Code in Laravel verwenden? –

+0

Warum nicht. Holen Sie sich Ihren API-Schlüssel, bevor Sie den Code –

+0

verwenden Ich füge meine Controller-Seite in meine Frage –

Verwandte Themen