Pop\Geo\Geo::distanceTo PHP Method

distanceTo() public method

Get distance from current Geo object coordinates to another
public distanceTo ( Geo $dest, integer $round = 2, boolean $km = false ) : mixed
$dest Geo
$round integer
$km boolean
return mixed
    public function distanceTo(Geo $dest, $round = 2, $km = false)
    {
        $distance = null;
        if (null === $this->latitude || null === $this->longitude) {
            throw new Exception('The origin coordinates are not set.');
        }
        if (null === $dest->getLatitude() || null === $dest->getLongitude()) {
            throw new Exception('The destination coordinates are not set.');
        }
        $origin = array('latitude' => $this->latitude, 'longitude' => $this->longitude);
        $destination = array('latitude' => $dest->getLatitude(), 'longitude' => $dest->getLongitude());
        return self::calculateDistance($origin, $destination, $round, $km);
    }

Usage Example

Example #1
0
 public function testDistanceTo()
 {
     $geo1 = new Geo(array('latitude' => '30.006003', 'longitude' => '-90.10947'));
     $geo2 = new Geo(array('latitude' => '32.919104', 'longitude' => '-96.77497'));
     $this->assertEquals(441.24, $geo1->distanceTo($geo2, 2));
 }
All Usage Examples Of Pop\Geo\Geo::distanceTo