Location\Formatter\Coordinate\DMS::format PHP Method

format() public method

public format ( Coordinate $coordinate ) : string
$coordinate Location\Coordinate
return string
    public function format(Coordinate $coordinate)
    {
        $lat = $coordinate->getLat();
        $lng = $coordinate->getLng();
        $latValue = abs($lat);
        $latDegrees = intval($latValue);
        $latMinutesDecimal = $latValue - $latDegrees;
        $latMinutes = intval(60 * $latMinutesDecimal);
        $latSeconds = 60 * (60 * $latMinutesDecimal - $latMinutes);
        $lngValue = abs($lng);
        $lngDegrees = intval($lngValue);
        $lngMinutesDecimal = $lngValue - $lngDegrees;
        $lngMinutes = intval(60 * $lngMinutesDecimal);
        $lngSeconds = 60 * (60 * $lngMinutesDecimal - $lngMinutes);
        return sprintf("%s%02d%s %02d%s %02d%s%s%s%s%03d%s %02d%s %02d%s%s", $this->getLatPrefix($lat), abs($latDegrees), $this->units[$this->unitType]['deg'], $latMinutes, $this->units[$this->unitType]['min'], round($latSeconds, 0), $this->units[$this->unitType]['sec'], $this->getLatSuffix($lat), $this->separator, $this->getLngPrefix($lng), abs($lngDegrees), $this->units[$this->unitType]['deg'], $lngMinutes, $this->units[$this->unitType]['min'], round($lngSeconds, 0), $this->units[$this->unitType]['sec'], $this->getLngSuffix($lng));
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Location\Formatter\Coordinate\DMS::format
  */
 public function testFormatASCIIUnits()
 {
     $coordinate = new Coordinate(-18.911306, -155.678268);
     $this->formatter->setSeparator(", ")->setUnits(DMS::UNITS_ASCII);
     $this->assertEquals("-18° 54' 41\", -155° 40' 42\"", $this->formatter->format($coordinate));
 }