Location\Bounds::getCenter PHP Method

getCenter() public method

Calculates the center of this bounds object and returns it as a Coordinate instance.
public getCenter ( ) : Coordinate
return Coordinate
    public function getCenter()
    {
        $centerLat = ($this->getNorth() + $this->getSouth()) / 2;
        return new Coordinate($centerLat, $this->getCenterLng());
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Location\Bounds::getCenter
  */
 public function testGetCenter()
 {
     $testBounds = [['nw' => new Coordinate(50, 10), 'se' => new Coordinate(30, 30), 'c' => new Coordinate(40, 20)], ['nw' => new Coordinate(50, -130), 'se' => new Coordinate(30, -110), 'c' => new Coordinate(40, -120)], ['nw' => new Coordinate(10, -10), 'se' => new Coordinate(-10, 10), 'c' => new Coordinate(0, 0)], ['nw' => new Coordinate(-80, -130), 'se' => new Coordinate(-90, -110), 'c' => new Coordinate(-85, -120)], ['nw' => new Coordinate(80, -130), 'se' => new Coordinate(90, -110), 'c' => new Coordinate(85, -120)], ['nw' => new Coordinate(80, 110), 'se' => new Coordinate(90, 130), 'c' => new Coordinate(85, 120)], ['nw' => new Coordinate(50, 170), 'se' => new Coordinate(30, -160), 'c' => new Coordinate(40, -175)], ['nw' => new Coordinate(-50, 150), 'se' => new Coordinate(-70, -170), 'c' => new Coordinate(-60, 170)]];
     foreach ($testBounds as $bounds) {
         $b = new Bounds($bounds['nw'], $bounds['se']);
         $this->assertEquals($bounds['c'], $b->getCenter());
     }
 }