Location\Formatter\Coordinate\DecimalMinutes::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 = 60 * $latMinutesDecimal;
        $lngValue = abs($lng);
        $lngDegrees = intval($lngValue);
        $lngMinutesDecimal = $lngValue - $lngDegrees;
        $lngMinutes = 60 * $lngMinutesDecimal;
        return sprintf("%s%02d%s %s%s%s%s%s%03d%s %s%s%s", $this->getLatPrefix($lat), abs($latDegrees), $this->units[$this->unitType]['deg'], number_format($latMinutes, $this->digits, $this->decimalPoint, $this->decimalPoint), $this->units[$this->unitType]['min'], $this->getLatSuffix($lat), $this->separator, $this->getLngPrefix($lng), abs($lngDegrees), $this->units[$this->unitType]['deg'], number_format($lngMinutes, $this->digits, $this->decimalPoint, $this->decimalPoint), $this->units[$this->unitType]['min'], $this->getLngSuffix($lng));
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Location\Formatter\Coordinate\DMS::format
  */
 public function testSetDecimalPoint()
 {
     $coordinate = new Coordinate(-18.911306, -155.678268);
     $this->formatter->setDecimalPoint(',');
     $this->assertEquals("-18° 54,678′ -155° 40,696′", $this->formatter->format($coordinate));
 }