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条回答 默认 最新

  • doutang6819 2016-08-23 09:50
    关注

    You need to use Reverese Geocoding. Google maps API would be the best choice.

    <?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;
      }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想通过python处理sybase IQ库的一些数据,但是不知道sybase IQ库怎么连接,之前连接都是用linux上的 dbisql
  • ¥15 安装llama-cpp-python==0.1.83失败
  • ¥20 管道轴向耦合水击问题
  • ¥60 补全networkx TODO部分。
  • ¥15 有内推吗,云计算linux运维方向
  • ¥30 sort cuteSV.vcf by bcftools用IGV可视化出现报错
  • ¥100 SOS!对STK中导出的天体图像进行质心提取有没有人做过啊
  • ¥15 python 欧式距离
  • ¥15 运行qteasy报错
  • ¥15 遗传算法解决有工序顺序约束的大规模FJSP问题