get() public méthode

Calculate the distance between two points. Defaults to Vincenty if no calculator is supplied. If no unit converter is supplied then the formula will return a value in metres.
public get ( Treffynnon\Navigator\Distance\Calculator\CalculatorInterface $calculator = null, Treffynnon\Navigator\Distance\Converter\ConverterInterface $unit_converter = null ) : float
$calculator Treffynnon\Navigator\Distance\Calculator\CalculatorInterface
$unit_converter Treffynnon\Navigator\Distance\Converter\ConverterInterface
Résultat float
 /**
  * @expectedException PHPUnit_Framework_Error
  */
 public function testFailedGet()
 {
     $point1 = new N\LatLong(new N\Coordinate(80.90000000000001), new N\Coordinate(20.1));
     $point2 = new N\LatLong(new N\Coordinate(20.1), new N\Coordinate(80.90000000000001));
     $Distance = new N\Distance($point1, $point2);
     $metres = $Distance->get(new stdClass(), new stdClass());
 }
 /**
  * @dataProvider coordValidProvider 
  */
 public function testConstructorWithProvider($coord)
 {
     $point1 = new N\LatLong(new N\Coordinate($coord), new N\Coordinate($coord - 15));
     $point2 = new N\LatLong(new N\Coordinate($coord - 5), new N\Coordinate($coord));
     $Distance = new N\Distance($point1, $point2);
     $metres = $Distance->get();
     $this->assertGreaterThan(20, $metres);
 }
Exemple #3
0
/**
 * Calculate distance between two points
 *
 * @param float $lat1
 * @param float $long1
 * @param float $lat2
 * @param float $long2
 * @return float	Distance in meters
 */
function get_distance($lat1, $long1, $lat2, $long2, $unit = 'metres')
{
    $point1 = new LatLong(new Coordinate($lat1), new Coordinate($long1));
    $point2 = new LatLong(new Coordinate($lat2), new Coordinate($long2));
    $distance = new Distance($point1, $point2);
    return $distance->get(new GreatCircle());
}