/** * @param GetMapObjectsMessage $msg * @param int $width */ protected function addCellIds(GetMapObjectsMessage $msg, $width = 6) { $latLng = S2LatLng::fromDegrees($this->session->getLocation()->getLatitude(), $this->session->getLocation()->getLongitude()); $cellId = S2CellId::fromLatLng($latLng)->parent(15); $size = 2 ** (S2CellId::MAX_LEVEL - $cellId->level()); $iIndex = 0; $jIndex = 0; $face = $cellId->toFaceIJOrientation($iIndex, $jIndex); $halfWidth = (int) floor($width / 2); for ($x = -$halfWidth; $x <= $halfWidth; $x++) { for ($y = -$halfWidth; $y <= $halfWidth; $y++) { $msg->addCellId(S2CellId::fromFaceIJ($face, $iIndex + $x * $size, $jIndex + $y * $size)->parent(15)->id()); } } }