<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
header('Content-type: application/json; charset=utf-8');
$point1=$_REQUEST['pickup'];
$point2=$_REQUEST['dropoff'];

if(!empty($point1) && !empty($point2))
{
    $dist=GetDrivingDistance($point1, $point2);
    echo $dist;
}

//calculate distance
function GetDrivingDistance($marker1, $marker2)
{
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".urlencode($marker1)."&destinations=".urlencode($marker2)
           ."&mode=driving&sensor=false&key=AIzaSyCq_JZBDbrE5qma5SgF06M2dVAqbiZBZ-o";
    $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 json_encode(array('distance' => $dist, 'time' => $time), true);
}