/** * Get the distance between this point and another point in meters. * * @param TrackPoint $trackPoint The other point. * @return float The distance in meters. */ public function distance(TrackPoint $trackPoint) { $earthRadius = 6371000; $latFrom = deg2rad($this->getLatitude()); $lonFrom = deg2rad($this->getLongitude()); $latTo = deg2rad($trackPoint->getLatitude()); $lonTo = deg2rad($trackPoint->getLongitude()); $latDelta = $latTo - $latFrom; $lonDelta = $lonTo - $lonFrom; $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2))); return $angle * $earthRadius; }
/** * Flatten a track point to be posted on endomondo. * * @param TrackPoint $trackPoint The track point to flatten. * @param float $distance The total distance the point in meters. * @param float $speed The speed the point in km/h from the previous point. * @return string */ private function flattenTrackPoint(TrackPoint $trackPoint, $distance, $speed) { $dateTime = clone $trackPoint->getDateTime(); $dateTime->setTimezone(new \DateTimeZone('UTC')); return $this->formatEndomondoTrackPoint($dateTime, self::INSTRUCTION_START, $trackPoint->getLatitude(), $trackPoint->getLongitude(), $distance, $speed, $trackPoint->getElevation(), $trackPoint->hasExtension(HR::ID) ? $trackPoint->getExtension(HR::ID)->getValue() : ''); }