/** * Get distance from current Geo object coordinates to another * * @param Geo $dest * @param int $round * @param boolean $km * @throws Exception * @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 = ['latitude' => $this->latitude, 'longitude' => $this->longitude]; $destination = ['latitude' => $dest->getLatitude(), 'longitude' => $dest->getLongitude()]; return self::calculateDistance($origin, $destination, $round, $km); }
/** * Formats a geo. * * @param \Libreworks\Microformats\Geo $geo The geo coordinates * @return string The HTML markup */ public function format(Geo $geo) { return '<span class="h-geo">' . '<span class="p-latitude">' . (string) $geo->getLatitude() . '</span>, ' . '<span class="p-longitude">' . (string) $geo->getLongitude() . '</span>' . ($geo->getAltitude() === null ? '' : ' (elevation <span class="p-altitude">' . (string) $geo->getAltitude() . '</span>)') . '</span>'; }