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;
 }