Exemplo n.º 1
0
 /**
  * onExistLatLng
  * @param float $lat
  * @param float $lng
  * @return boolean | Geocoder\Model\AddressCollection
  */
 protected function onExistLatLng($lat, $lng)
 {
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $result = $geocoder->reverse($lat, $lng);
     if ($result) {
         return $result;
     }
     return false;
 }
 /**
  * Returns current address information from visitor
  *
  * @return mixed
  */
 public function getAddressAction()
 {
     $longitude = $this->request->getPost('longitude');
     $latitude = $this->request->getPost('latitude');
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $address = $geocoder->reverse($longitude, $latitude)->first();
     $data = ['streetName' => $address->getStreetName(), 'streetNumber' => $address->getStreetNumber(), 'country' => ['name' => $address->getCountry()->getName(), 'string' => $address->getCountry()->toString(), 'code' => $address->getCountry()->getCode()], 'city' => $address->getLocality(), 'subCity' => $address->getSubLocality()];
     $this->response->setContent(json_encode($data));
     return $this->response;
 }
Exemplo n.º 3
0
 protected function insertTranslation($entity)
 {
     $httpAdapter = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($httpAdapter, null, null, true, 'AIzaSyDzmQiEmu390yCXaB9RQ4jFwXnm_hEJJBI');
     foreach ($this->locales as $lng) {
         $geocoder->setLocale($lng);
         $result = $geocoder->reverse($entity->getLat(), $entity->getLng())->first();
         //var_dump($result);
         $entity->setFormatted($result->getStreetNumber() . ', ' . $result->getStreetName() . ', ' . $result->getLocality() . ', ' . $result->getAdminLevels()->first()->getName() . ', ' . $result->getCountry()->getName());
         $entity->translate($lng)->setCountry($result->getCountry()->getName())->setState($result->getAdminLevels()->first()->getName())->setCity($result->getLocality())->setStreet($result->getStreetName())->setStreetNumber($result->getStreetNumber());
         $entity->mergeNewTranslations();
     }
     //$entity->setFormatted($entity->getStreetNumber() . ', ' . $entity->getStreet() . ', ' . $entity->getCity() . ', ' . $entity->getState() . ', ' . $entity->getCountry());
     //$this->entities[] = $entity;
     //$this->em->flush();
     //        $geocoder = $this->container
     //            ->get('bazinga_geocoder.geocoder')->using('google_maps')->getLocale()
     //        ;
     //die();
 }
 /**
  * Retrieves weather for current location from user
  *
  * @return mixed
  */
 public function weatherForCurrentLocationAction()
 {
     $longitude = $this->request->getPost('longitude');
     $latitude = $this->request->getPost('latitude');
     if ($longitude != 0 && $latitude != 0) {
         $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
         $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
         $address = $geocoder->reverse($longitude, $latitude)->first();
         $city = $address->getLocality();
         $weather = new Weather();
         $cityVars = json_decode($weather->getCityVars($city));
         $this->response->setContent(json_encode($cityVars));
         return $this->response;
     }
 }