geocode() public method

{@inheritDoc}
public geocode ( $address )
 /**
  * @param string $city
  * @param bool $openInWeekends
  * @param bool $hasSupportDesk
  * @param bool $strict
  * @return array offices
  */
 public function getOfficesByLocation($city, $openInWeekends, $hasSupportDesk, $strict)
 {
     $offices = Office::query();
     if (filter_var($openInWeekends, FILTER_VALIDATE_BOOLEAN)) {
         $offices->where('is_open_in_weekends', '=', 'Y');
     }
     if (filter_var($hasSupportDesk, FILTER_VALIDATE_BOOLEAN)) {
         $offices->where('has_support_desk', '=', 'Y');
     }
     if (!filter_var($strict, FILTER_VALIDATE_BOOLEAN)) {
         $bounds = $this->geocoder->geocode($city)->first()->getBounds();
         $offices->where('latitude', '<', $bounds->getNorth());
         $offices->where('latitude', '>', $bounds->getSouth());
         $offices->where('longitude', '<', $bounds->getEast());
         $offices->where('longitude', '>', $bounds->getWest());
     } else {
         $offices->where('city', '=', $city);
     }
     return $offices->get();
 }
Example #2
0
 /**
  * Gets for input string containing address or ip
  * @param string $streetAddressOrIp
  * @return AddressCollection
  */
 public static function getLocationData($streetAddressOrIp)
 {
     $curl = new CurlHttpAdapter();
     if (filter_var($streetAddressOrIp, FILTER_VALIDATE_IP)) {
         $reader = new Reader(Yii::getAlias('@geolocation/data/GeoLite2-Country.mmdb'));
         $adapter = new GeoIP2Adapter($reader);
         $geocoder = new GeoIP2($adapter);
     } else {
         $geocoder = new GoogleMaps($curl);
     }
     return $geocoder->geocode($streetAddressOrIp);
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($this->isMain == 1) {
         self::updateAll(['isMain' => 0], ['entity' => $this->entity, 'entity_id' => $this->entity_id]);
         $this->isMain = 1;
     }
     try {
         $curl = new CurlHttpAdapter();
         $geolocation = new GoogleMaps($curl, null, null, true);
         //,'AIzaSyC-N0Ri1TejcIrR0k9tZ0rFjQWe6vU2aaY' not supported by this adapter
         $lookupaddress = urldecode($this->addresslineOne . ' - ' . $this->cityName);
         //utf8_encode(str_replace(' ','+',$this->addresslineOne . ' - ' . $this->cityName));
         $address = $geolocation->geocode($lookupaddress);
         if ($address->getLatitude() != '') {
             $this->latitude = $address->getLatitude();
             $this->longitude = $address->getLongitude();
         }
     } catch (HttpAdapterException $e) {
         \Yii::error($e->getResponse(), 'net\\frenzel\\cmaddress');
     }
     return parent::beforeSave($insert);
 }
Example #4
0
 /**
  * @expectedException \Geocoder\Exception\InvalidCredentials
  * @expectedExceptionMessage API key is invalid https://maps.googleapis.com/maps/api/geocode/json?address=Columbia%20University&key=fake_key
  */
 public function testGeocodeWithRealInvalidApiKey()
 {
     $provider = new GoogleMaps($this->getAdapter(), null, null, true, $this->testAPIKey);
     $provider->geocode('Columbia University');
 }