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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?