如何在PHP中计算两公里之间的距离?

I have a table in which I am storing the service and columns of service table is lattitude, longitude i.e location of a service.

Now I want to get the current location of the user and search the services available around 10 kilometers distance to the user.

For this I searched how to calculate the distance between two locations and tried one of the code but it is giving me some syntax error in JSON.

The error is syntax error, (unexpected 'S'), also I don't get the result in kilometers by this formula.

     public function searchVendors($lattitudeFrom,$longitudeFrom)
    {
        $lattitudeTo = -10.4212157;
        $longitudeTo = 28.6031842;


        $dist = $this -> haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000);

        return $dist;

    }

 public function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000)
{
    // convert from degrees to radians
    $latFrom = deg2rad($latitudeFrom);
    $lonFrom = deg2rad($longitudeFrom);
    $latTo = deg2rad($latitudeTo);
    $lonTo = deg2rad($longitudeTo);

    $latDelta = $latTo - $latFrom;
    $lonDelta = $lonTo - $lonFrom;

    $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
        cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
    return $angle * $earthRadius;
}

getVendors.php

  <?php

header("Content-type: application/json");

   // if ( $_SERVER['REQUEST_METHOD']=='POST') {
        include_once ("../include/Vendor.php");
    try {

    $con = DB::getConnection();

    $raw = file_get_contents("php://input");
    $data = json_decode($raw, true);

    $longitude = $data->longitude;
    $lattitude = $data->lattitude;

    $v = new Vendor();
    $response = $v -> searchVendors($lattitude,$longitude);


    json_encode($response);


    echo $response;

        if ( $response == null ) {
            $response = json_encode(array("result" => -2, "message" => "Empty result"));
            echo $response;
        } else {
            echo $response;
        }
    } catch(Exception $e) {
        $result = array("result" => -1, "message" => $e -> getMessage());
        echo json_encode($result);
        }
//}
?>

How can I achieve this? Can anyone help please.. Very new in php.

php cal_dist(a,b,key=none,spec=km)

Try this code for find distance in KM or MILES

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

      $theta = $lon1 - $lon2;
      $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
      $dist = acos($dist);
      $dist = rad2deg($dist);
      $miles = $dist * 60 * 1.1515;
      $unit = strtoupper($unit);

      if ($unit == "K") {
        return ($miles * 1.609344);
      } else if ($unit == "N") {
          return ($miles * 0.8684);
        } else {
            return $miles;
          }
    }