vendredi 6 mai 2016

How to find min&max in array push

I am doing a api for cab booking app like uber.I am using distancematrix to find the distance between two latitude and longitude.In that single customer have multiple drivers around it.I would like to find nearest driver using single customer latitude and longitude over multiple driver latitude and longitude.How can i find min&max distance of driver and get min&max value based on driver id.

Below code i am using to find the nearest driver:

<?php
        function GetDrivingDistance($lat1, $lat2, $long1, $long2)
        {
            $url = "http://ift.tt/1vgsFPu".$lat1.",".$long1."&destinations=".$lat2.",".$long2."&mode=driving&language=pl-PL";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            $response = curl_exec($ch);
            curl_close($ch);
            $response_a = json_decode($response, true);
            $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
            $time = $response_a['rows'][0]['elements'][0]['duration']['text'];

            return array('distance' => $dist, 'time' => $time);
            //return $distance;
        }

    $cus_latlong_qry="SELECT * FROM customer_position WHERE customer_id='$customer_id'";
    $cus_latlong_exe=mysqli_query($con,$cus_latlong_qry);
    $cus_latlong_res=mysqli_fetch_array($cus_latlong_exe);
    $cus_lat=$cus_latlong_res['latitude'];
    $cus_long=$cus_latlong_res['longtitude'];

$driver_latlong_qry="SELECT * FROM driver_position WHERE driver_type='$_GET[type_id]' AND (booking_status='3' OR booking_status='2') AND active_status='0'";

                $driver_latlong_exe=mysqli_query($con,$driver_latlong_qry);
                $minimumvalue=array();
                $distance=array();
                while($driver_latlong_res=mysqli_fetch_array($driver_latlong_exe))
                {
                    $driv_id=$driver_latlong_res['driver_id'];
                    $driv_lat=$driver_latlong_res['lattitude'];
                    $driv_long=$driver_latlong_res['longtitude'];
                    $dist = GetDrivingDistance($cus_lat,$driv_lat,$cus_long,$driv_long);
                    array_push($distance,$dist);
                }

?>

here how can i find min&mx distance in array push with respect to particular driver id..??



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1XbIR4t
via IFTTT

Aucun commentaire:

Enregistrer un commentaire