<?php 
 $latitude = $_POST['lat'];
 $longitude = $_POST['lng'];
 $mobile_lat = $_POST['mobile_lat'];
 $mobile_lng = $_POST['mobile_lng'];
 //echo "lat:".$latitude."moblat:".$mobile_lat;
 $data= array();
 $distanceTime = GetDrivingDistance($latitude, $longitude, $mobile_lat, $mobile_lng);
                    $data['nxt_bstp_distance'] = $distanceTime['distance'];
                    $data['add_time'] = strtotime(date("Y-m-d H:i:s")) + strtotime(date("Y-m-d H:i:s", $distanceTime['timesec']));
                    $data['nxt_eta_time'] = date("d-m-Y h:i:s a",  $data['add_time']);
                    //$data['nxt_eta_time'] = date('H:i:s', $add_time);
                    
                    die(json_encode($data));
  
 function GetDrivingDistance($lat1, $long1, $lat2, $long2) {

    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . $lat1 . "," . $long1 . "&destinations=" . $lat2 . "," . $long2 . "&mode=driving&language=en-EN";
    //echo $url;
    $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);
    //print_r($response_a);
    $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
    $time = $response_a['rows'][0]['elements'][0]['duration']['text'];
    $timesec = $response_a['rows'][0]['elements'][0]['duration']['value'];
    $status = $response_a['rows'][0]['elements'][0]['status'];

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