Author: William Durand (william.durand1@gmail.com)
Inheritance: extends AbstractHttpProvider, implements Geocoder\Provider\LocaleAwareProvider, use trait Geocoder\Provider\LocaleTrait
示例#1
0
 /**
  * usage e.g.
  * ```
  * use \dbsparkleTeam\unispot\formatters\AddressFormatter;
  * use \dbsparkleTeam\unispot\components\Location;
  *
  * Location::getAddress(60.023554,30.2232882,[
  *     'type' => AddressFormatter::TYPE_FULL,
  *     'format' => AddressFormatter::FORMAT_NORMAL
  * ])
  * ```
  * @param float $lat
  * @param float $lng
  * @param array $options
  * @return string
  */
 public static function getAddress($lat, $lng, $options = [])
 {
     $curl = new CurlHttpAdapter();
     $geocoder = new GoogleMaps($curl);
     $addressData = $geocoder->reverse($lat, $lng);
     if (!isset($options['format']) || !in_array($options['format'], [AddressFormatter::FORMAT_NORMAL, AddressFormatter::FORMAT_REVERSED])) {
         $options['format'] = AddressFormatter::FORMAT_NORMAL;
     }
     if (!isset($options['type']) || !in_array($options['type'], [AddressFormatter::TYPE_FULL, AddressFormatter::TYPE_SHORT])) {
         $options['type'] = AddressFormatter::TYPE_FULL;
     }
     return AddressFormatter::format($addressData->first(), $options);
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 protected function buildQuery($query)
 {
     $query = parent::buildQuery($query);
     $query = sprintf('%s&client=%s', $query, $this->clientId);
     if (null !== $this->privateKey) {
         $query = $this->signQuery($query);
     }
     return $query;
 }
 /**
  * @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();
 }
示例#4
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);
 }
示例#5
0
 protected function buildQuery($query)
 {
     return parent::buildQuery($this->proxy . '?' . parse_url($query, PHP_URL_QUERY));
 }
示例#6
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');
 }