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 matlab数字图像处理频率域滤波
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行