PHP Classes

File: src/Tools.php

Recommend this page to a friend!
  Classes of Joseluis Laso   jlaso GPS   src/Tools.php   Download  
File: src/Tools.php
Role: Class source
Content type: text/plain
Description: Class source
Class: jlaso GPS
Calculate the distance between geographic points
Author: By
Last change: Update of src/Tools.php
Date: 4 months ago
Size: 807 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

namespace
JLaso\Gps;

/**
 * Class Tools
 * @package JLaso\Gps
 * @author Joseluis Laso <jlaso@joseluislaso.es>
 */

class Tools
{

    public static function
distance(float $latitude1, float $longitude1, float $latitude2, float $longitude2): float
   
{
       
$dLatitude = ($latitude2 - $latitude1) / 2;
       
$dLongitude = ($longitude2 - $longitude1) / 2;
       
$tmp = sin(deg2rad($dLatitude)) * sin(deg2rad($dLatitude)) +
                       
cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin(deg2rad($dLongitude)) * sin(deg2rad($dLongitude));
       
$aux = asin(min(1, sqrt($tmp)));

        return
round(12745.9728 * $aux, 4);
    }

    public static function
toMiles(float $value): float
   
{
        return
0.621 * $value;
    }

}