/** @var Ivory\GoogleMapBundle\Model\Map */
 public function generateGoogleMapAction($address, $city)
 {
     $locationInfo = [$address, $city];
     $map = $this->get('ivory_google_map.map');
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($locationInfo[0]) . '+' . urlencode($locationInfo[1]));
     $obj = json_decode($json);
     if (count($obj->results) === 0) {
         return $this->render('ConnectHollandPiccoloContentBundle:Block:googlemap.html.twig', array('map' => $map));
     }
     $location = $geocoder->geocode($locationInfo[0] . ' ' . $locationInfo[1])->first();
     $latitude = $location->getLatitude();
     $longitude = $location->getLongitude();
     $map->setCenter($latitude, $longitude, true);
     $map->setMapOption('zoom', 12);
     $marker = new Marker();
     $marker->setPosition($latitude, $longitude, true);
     $marker->setOption('clickable', true);
     $map->addMarker($marker);
     $infoWindow = new InfoWindow();
     $infoWindow->setContent('<p>' . $locationInfo[0] . '<br/>' . $locationInfo[1] . '</p>');
     $infoWindow->setAutoClose(true);
     $marker->setInfoWindow($infoWindow);
     return $this->render('ConnectHollandPiccoloContentBundle:Block:googlemap.html.twig', array('map' => $map));
 }
Example #2
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;
 }
 /**
  * onLatLngGetting
  * @param Model $model
  * @return array | boolean
  */
 protected function onLatLngGetting(Model $model)
 {
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $model->loadModel('Country');
     $aCountryOptions = $model->Country->options();
     $countryCode = $model->data['User']['live_country'];
     $countryName = isset($aCountryOptions[$countryCode]) ? $aCountryOptions[$countryCode] : $countryCode;
     $address = join(',', array($model->data['User']['live_address'], $model->data['User']['live_place'], $countryName));
     $result = $geocoder->geocode($address);
     if ($result) {
         return $result;
     }
     return false;
 }
Example #5
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();
 }
Example #6
0
 public function pre_save($post_id, $new, $old)
 {
     if (empty($new['lat']) or empty($new['lng']) and !empty($this->_params['geocode'])) {
         $address = array();
         foreach ($this->_params['geocode'] as $field) {
             empty($_POST[$field]) or $address[] = $_POST[$field];
         }
         if (!empty($address)) {
             try {
                 $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
                 $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
                 $address_collection = $geocoder->geocode(implode(' ', $address));
                 if (!empty($address_collection)) {
                     $new['lat'] = $address_collection->first()->getLatitude();
                     $new['lng'] = $address_collection->first()->getLongitude();
                 }
             } catch (\Exception $ex) {
             }
         }
     }
     return parent::pre_save($post_id, $new, $old);
 }
 /**
  * @param string $postal_code
  *
  * @return LatLon
  *
  * @throws GeocodingException
  */
 public function geocode($postal_code)
 {
     // Setup local variable for holding results from geocoder.
     $addressCollection = null;
     // Try to call the geocoder.
     try {
         // Set it call to geocoder...
         $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
         $geocoder = new \Geocoder\Provider\GoogleMaps($curl, null, null, true);
         // Geocode the zipcode...
         $addressCollection = $geocoder->geocode($postal_code);
     } catch (\Exception $exception) {
         // Recover from exception by rethrowing wrapped in GeocodingException.
         throw new GeocodingException('An exception occurred during geocoding.', 0, $exception);
     }
     // Make sure geocode found at least one result.
     if (!$addressCollection->has(0)) {
         throw new GeocodingException('ZIP code geocode did not return any results: ' . $postal_code);
     }
     // Store first result in local variable.
     $address = $addressCollection->get(0);
     // Return result.
     return new LatLon($address->getLatitude(), $address->getLongitude());
 }
Example #8
0
<?php

/**
 * Created by PhpStorm.
 * User: junior
 * Date: 15/11/2015
 * Time: 23:40
 */
require_once __DIR__ . "/../vendor/autoload.php";
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
$geocoder = new \Geocoder\Provider\GoogleMaps($curl);
$store = $geocoder->geocode('420 9th Avenue, New York, NY 10001 USA')->first();
$latitude = $store->getLatitude();
$longitude = $store->getLongitude();
echo $latitude, ':', $longitude;
 /**
  * @inheritDoc
  */
 public function save(\Profile\Entity\Profile $record)
 {
     $hydrator = new ClassMethods(true);
     $id = (int) $record->getId();
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $request = $geocoder->geocode($record->getAddress());
     if ($record->getAddress()) {
         $record->setLatitude($request->first()->getLatitude());
         $record->setLongitude($request->first()->getLongitude());
     }
     // extract the data from the object
     $data = $hydrator->extract($record);
     $this->getEventManager()->trigger(__FUNCTION__ . '.pre', null, array('data' => $data));
     // Trigger an profile
     if ($id == 0) {
         unset($data['id']);
         $data['createdat'] = date('Y-m-d H:i:s');
         $data['updatedat'] = date('Y-m-d H:i:s');
         $this->tableGateway->insert($data);
         // add the record
         $id = $this->tableGateway->getLastInsertValue();
     } else {
         $rs = $this->find($id);
         if (!empty($rs)) {
             $data['updatedat'] = date('Y-m-d H:i:s');
             unset($data['createdat']);
             unset($data['slug']);
             $this->tableGateway->update($data, array('id' => $id));
         } else {
             throw new \Exception('Record ID does not exist');
         }
     }
     $record = $this->find($id);
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', null, array('id' => $id, 'data' => $data, 'record' => $record));
     // Trigger an profile
     return $record;
 }
Example #10
0
 /**
  * Set latlong
  *
  * @param string $latlong
  *
  * @return Oferty
  */
 public function setLatLong()
 {
     $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
     // get curl config
     $conf = $curl->getConfiguration();
     // set timeout
     $conf->setTimeout(1000);
     // save config
     $curl->setConfiguration($conf);
     $geocoder = new \Geocoder\Provider\GoogleMaps($curl);
     $adress = $geocoder->geocode($this->miasto . ' ' . $this->ulica . ' ' . $this->numer);
     if ($adress->count() != 0) {
         $this->longitude = $adress->first()->getLongitude();
         $this->latitude = $adress->first()->getLatitude();
     } else {
         $this->longitude = 300;
         $this->latitude = 300;
     }
     return $this;
 }
 /**
  * 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;
     }
 }