/** * @param $venue * * @return Geoname */ public function getGeoname($venue) { $address = new Address(); $address->setLat($venue['location']['lat']); $address->setLng($venue['location']['lng']); if (isset($venue['location']['city'])) { $address->setCity($venue['location']['city']); } if (isset($venue['location']['country'])) { $address->setCountry($venue['location']['country']); } if (isset($venue['location']['state'])) { $address->setCounty($venue['location']['state']); } if (isset($venue['location']['postalCode'])) { $address->setPostalCode($venue['location']['postalCode']); } $geoname = $this->geonameRepository->getOneByAddress($address); return $geoname; }
/** * @param FullPlaceResult $place * @return Address * * @throws UnresolvedGeonameException */ public function createFromFullPlaceResult(FullPlaceResult $place) { $address = new Address(); $address->setCity($place->getCity()); $address->setLat($place->getLatitude()); $address->setLng($place->getLongitude()); $address->setCountry($place->getCountry()); $address->setCountryCode($place->getCountryCode()); $address->setFormattedAddress($place->getFormattedAddress()); $address->setRegion($place->getRegion()); $address->setRegionCode($place->getRegionCode()); $address->setCounty($place->getCounty()); $address->setCountyCode($place->getCountyCode()); $address->setCity($place->getCity()); $address->setPostalCode($place->getPostalCode()); $address->setStreetName($place->getStreetName()); $address->setStreetNumber($place->getStreetNumber()); $geoname = $this->geonameRepository->getOneByAddress($address); $address->setGeoname($geoname); return $address; }
/** * @ApiDoc( * description="Check Public Api Status", * statusCodes={200="Success"}, * section="Public Api" * ) * @Route("/public-api/performance") * @Template{} * @Method({"GET"}) * @return mixed */ public function performanceAction() { $stopwatch = new Stopwatch(); $stopwatch->start('main'); $address = new Address(); $address->setCity('London'); $address->setCountry('GB'); $address->setLat('51.5286416'); $address->setLng('-0.1015987'); $geoname = $this->geonameRepository->getOneByAddress($address); $stopwatch->lap('main'); $cuisines = $this->cuisineRepository->findAll(); $event = $stopwatch->stop('main'); $duration = $event->getDuration(); $endTime = $event->getEndTime(); $memory = $event->getMemory(); $periodsData = array(); foreach ($event->getPeriods() as $period) { $periodsData[] = array('duration' => $period->getDuration(), 'memory' => $period->getMemory()); } return $this->view(array('duration' => $duration, 'endTime' => $endTime, 'memory' => $memory, 'periods' => $periodsData, 'geoname' => $geoname, 'cuisines' => $cuisines)); }
/** * @param int $id * * @ApiDoc( * description="GooglePlace search", * statusCodes={200="Address GooglePlace"}, * section="Google Place") * @Route("/api/google-places/place-results/{id}") * @throws BadRequestException * @Method({"GET"}) * @Cache(maxage="+1 week", public=true) * @return View */ public function getAction($id) { $place = $this->googlePlaceClient->detail($id); $address = new Address(); $address->setCity($place->getCity()); $address->setLat($place->getLatitude()); $address->setLng($place->getLongitude()); $geoname = $this->geonameRepository->getOneByAddress($address); $place->setGeoname($geoname); return $this->view(array('placeResult' => $place)); }
/** * @param ResultInterface $result * * @return Address */ public function geocoderResultToAddress(ResultInterface $result) { $address = new Address(); $address->setCity($result->getCity()); $address->setCountry($result->getCountry()); $address->setCountryCode($result->getCountryCode()); $address->setRegion($result->getRegion()); $address->setRegionCode($result->getRegionCode()); $address->setCounty($result->getCounty()); $address->setCountyCode($result->getCountyCode()); $address->setLat($result->getLatitude()); $address->setLng($result->getLongitude()); $address->setPostalCode($result->getZipcode()); $address->setStreetName($result->getStreetName()); $address->setStreetNumber($result->getStreetNumber()); $this->addressManager->updateFormattedAddress($address); return $address; }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->formatOutput($output); $this->getDependencies(); $latitude = $input->getOption('latitude'); $longitude = $input->getOption('longitude'); $radius = $input->getOption('radius'); $city = $input->getOption('city'); if (!$city && !($latitude && $longitude)) { return $output->writeln('<error>Insert city parameter or latitude + longitude.</error>'); } if ($city) { $geocodedAddress = $this->geocoder->geocode($city); $latitude = $geocodedAddress->getLat(); $longitude = $geocodedAddress->getLng(); } $restaurants = array(); $nextPage = null; do { $output->writeln('Searching in google place'); $placeResults = $this->googlePlaceClient->search($latitude, $longitude, null, $radius, $nextPage); $nextPage = $placeResults->getNextPage(); foreach ($placeResults->toArray() as $placeResult) { $restaurant = new Restaurant(); $fullPlaceResult = $this->googlePlaceClient->detail($placeResult->getId()); $restaurant->setName($placeResult->getName()); $restaurant->setLat($fullPlaceResult->getLatitude()); $restaurant->setLng($fullPlaceResult->getLongitude()); $restaurant->setAddress($fullPlaceResult->getFormattedAddress()); $address = new Address(); $address->setCity($fullPlaceResult->getCity()); $address->setLat($fullPlaceResult->getLatitude()); $address->setLng($fullPlaceResult->getLongitude()); $address->setFormattedAddress($fullPlaceResult->getFormattedAddress()); $this->addressManager->hydrateGeoname($address); $restaurant->setGeoname($address->getGeoname()); $photosReferences = $fullPlaceResult->getPhotoReferences(); if (count($photosReferences) > 0) { $message = $this->googlePlaceClient->image($photosReferences[0]); $imageContent = $message->getContent(); $filename = $this->s3->uploadData($imageContent, 'restaurant/'); $restaurant->setPicture($filename); } $errors = $this->validator->validate($restaurant); if (count($errors) > 0) { $output->writeln(sprintf('<error>Import error:</error> %s ', (string) $errors)); } else { $restaurants[] = $restaurant; $this->entityManager->persist($restaurant); $output->writeln(sprintf('Imported: <info>%s</info> - %s', $restaurant->getName(), $address->getFormattedAddress())); } } } while ($nextPage); $this->entityManager->flush(); $output->writeln(sprintf('<success>Imported successfully %d Restaurants</success>', count($restaurants))); }