duanli6618
2016-08-23 09:40
浏览 28
已采纳

如何编写php代码将纬度经度值转换为laravel 5.2中的地址

i am fetching values from the database and displaying it into a table using php laravel. Latitude logitude value am fetching and displaying in my table. there is another column address, so in that column i need to display the address by converting corresponding lat long value from the database. Can anyone tell how i can write the code for that?

my view blade is giving below

    @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 page is

 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
        }

    }




}

Thanks in advance.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题