Example #1
0
 /**
  * @param $cellIds
  * @param $latitude
  * @param $longitude
  * @param $altitude
  * @return MapObjects
  */
 public function getMapObjectsCells($cellIds, $latitude, $longitude, $altitude)
 {
     $this->pokemonGoAPI->setLatitude((double) $latitude);
     $this->pokemonGoAPI->setLongitude((double) $longitude);
     $this->pokemonGoAPI->setAltitude((double) $altitude);
     if ($this->useCache && $this->pokemonGoAPI->currentTimeMillis() - $this->lastMapUpdate > $this->mapObjectsExpiry) {
         $this->lastMapUpdate = 0;
         $this->cachedMapObjects = new MapObjects($this->pokemonGoAPI);
     }
     $builder = new GetMapObjectsMessage();
     $builder->setLatitude((double) $this->pokemonGoAPI->getLatitude());
     $builder->setLongitude((double) $this->pokemonGoAPI->getLongitude());
     $index = 0;
     foreach ($cellIds as $cellId) {
         $builder->addCellId($cellId);
         $builder->addSinceTimestampMs($this->lastMapUpdate);
         $index++;
     }
     $serverRequest = new ServerRequest(RequestType::GET_MAP_OBJECTS, $builder);
     $this->pokemonGoAPI->getRequestHandler()->sendServerRequests($serverRequest);
     $response = new GetMapObjectsResponse($serverRequest->getData());
     $result = new MapObjects($this->pokemonGoAPI);
     foreach ($response->getMapCellsArray() as $mapCell) {
         $result->addNearbyPokemons($mapCell->getNearbyPokemonsArray());
         $result->addCatchablePokemons($mapCell->getCatchablePokemonsArray());
         $result->addWildPokemons($mapCell->getWildPokemonsArray());
         $result->addDecimatedSpawnPoints($mapCell->getDecimatedSpawnPointsArray());
         $result->addSpawnPoints($mapCell->getSpawnPointsArray());
         foreach ($mapCell->getFortsArray() as $fort) {
             if ($fort->getType() == FortType::GYM) {
                 $result->addGyms($fort);
             } elseif ($fort->getType() == FortType::CHECKPOINT) {
                 $result->addPokestops($fort);
             }
         }
     }
     if ($this->useCache) {
         $this->cachedMapObjects->update($result);
         $result = $this->cachedMapObjects;
         $this->lastMapUpdate = $this->pokemonGoAPI->currentTimeMillis();
     }
     return $result;
 }
 /**
  * @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());
         }
     }
 }