calculateDistance() public static method

Method to calculate the distance between 2 sets of coordinate
public static calculateDistance ( array $origin, array $destination, integer $round = 2, boolean $km = false ) : mixed
$origin array
$destination array
$round integer
$km boolean
return mixed
Esempio n. 1
0
 public function testCalculateDistance()
 {
     $dist = Geo::calculateDistance(array('latitude' => '32.919104', 'longitude' => '-96.77497'), array('latitude' => '30.006003', 'longitude' => '-90.10947'), 2, true);
     $this->assertEquals(710.11, $dist);
 }
Esempio n. 2
0
<?php

require_once '../../bootstrap.php';
use Pop\Geo\Geo;
try {
    $geo1 = new Geo(array('latitude' => '30.006003', 'longitude' => '-90.10947'));
    $geo2 = new Geo(array('latitude' => '32.919104', 'longitude' => '-96.77497'));
    echo $geo1->distanceTo($geo2, 2) . ' miles between New Orleans, LA and Dallas, TX.<br />';
    echo Geo::calculateDistance(array('latitude' => '32.919104', 'longitude' => '-96.77497'), array('latitude' => '30.006003', 'longitude' => '-90.10947'), 2, true) . ' kilometers between New Orleans, LA and Dallas, TX.';
} catch (\Exception $e) {
    echo $e->getMessage();
}