/** * Available placeholders: * * A - latitude as decimal * ad - latitude degrees * aU - latitude degrees without sign * am - latitude minutes * aM - latitude minutes with leading zero * as - latitude seconds * aS - latitude seconds with leading zero * aD - latitude direction * O - longitude as decimal * od - longitude degrees * oU - longitude degrees without sign * om - longitude minutes * oM - longitude minutes with leading zero * os - longitude seconds * oS - longitude seconds with leading zero * oD - longitude direction * * @param type $pattern * * @return string */ public function format($pattern) { $placeholderToValueMap = ['A' => (string) $this->latitude->asDecimal(), 'ad' => (string) ($this->latitude->sign() * $this->latitude->degrees()), 'aU' => (string) $this->latitude->degrees(), 'am' => (string) $this->latitude->minutes(), 'aM' => ($minutes = $this->latitude->minutes()) < 10 ? "0{$minutes}" : (string) $minutes, 'as' => (string) $this->latitude->seconds(), 'aS' => ($seconds = $this->latitude->seconds()) < 10 ? "0{$seconds}" : (string) $seconds, 'aD' => $this->latitude->sign() === 1 ? 'N' : 'S', 'O' => (string) $this->longitude->asDecimal(), 'od' => (string) ($this->longitude->sign() * $this->longitude->degrees()), 'oU' => (string) $this->longitude->degrees(), 'om' => (string) $this->longitude->minutes(), 'oM' => ($minutes = $this->longitude->minutes()) < 10 ? "0{$minutes}" : (string) $minutes, 'os' => (string) $this->longitude->seconds(), 'oS' => ($seconds = $this->longitude->seconds()) < 10 ? "0{$seconds}" : (string) $seconds, 'oD' => $this->longitude->sign() === 1 ? 'E' : 'W']; return str_replace(array_keys($placeholderToValueMap), array_values($placeholderToValueMap), $pattern); }