/** * Get the speed between this point and another point in km/h. * * @param TrackPoint $trackPoint The other point. * @return float */ public function speed(TrackPoint $trackPoint) { $start = $this->getDateTime(); $end = $trackPoint->getDateTime(); $dateDiff = $start->diff($end); $secondsDifference = $dateDiff->days * 86400 + $dateDiff->h * 3600 + $dateDiff->i * 60 + $dateDiff->s; if ($secondsDifference === 0) { return 0; } if ($this->hasDistance() === true && $trackPoint->hasDistance()) { $distance = abs($this->getDistance() - $trackPoint->getDistance()); } else { $distance = $this->distance($trackPoint); } return $distance / $secondsDifference * 3.6; }