Base class for those objects that make requests to the Google Web Services API
Author: Antonio Ramirez (amigo.cobos@gmail.com)
Inheritance: extends yii\base\Object
 /**
  * Makes a request for places nearby. Please, review the documentation on
  * https://developers.google.com/places/web-service/search#PlaceSearchResponses
  * for further information about the expected results.
  *
  * @param string $placeId Place ID
  * @param array $params parameters for the request. These override [GeocodingRequest::params].
  *
  * @return mixed|null
  * @throws \yii\base\InvalidConfigException
  */
 public function findPlaces(LatLng $location, $radius, $params = [])
 {
     $params['location'] = $location;
     $params['radius'] = $radius;
     $this->params = ArrayHelper::merge($this->params, $params);
     return parent::request();
 }
 /**
  * Calculates distances and travel times between origins and destinations
  * 
  * @param array $origins Addresses or coordinates
  * @param array $destinations Addresses or coordinates
  * @param array $params
  * @return mixed|null
  */
 public function calculate(array $origins, array $destinations, $params = [])
 {
     $params['origins'] = implode('|', $origins);
     $params['destinations'] = implode('|', $destinations);
     $this->params = ArrayHelper::merge($this->params, $params);
     return parent::request();
 }
 /**
  * Makes a geocoding request for an direction parameters. Please, review the documentation on
  * https://developers.google.com/maps/documentation/directions/intro#DirectionsResponses for further information about the
  * expected results.
  *
  * @param array $params parameters for the request. These override [DirectionsRequest::params].
  *
  * @return mixed|null
  * @throws \yii\base\InvalidConfigException
  */
 public function lookup($params = [])
 {
     $this->params = ArrayHelper::merge($this->params, $params);
     if ($this->params['origin'] == null && $this->params['destination'] == null) {
         throw new InvalidConfigException('"origin" and "destination" must be set for the request. Both cannot be null');
     }
     return parent::request();
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  * @param array $config
  */
 public function __construct($config = [])
 {
     $this->params = ArrayHelper::merge(['origin' => null, 'destination' => null, 'mode' => null, 'waypoints' => null, 'alternatives' => null, 'avoid' => null, 'language' => null, 'units' => null, 'region' => null, 'departure_time' => null, 'arrival_time' => null], $this->params);
     parent::__construct($config);
 }
 /**
  * Makes a request for a list of places fitting the query. Please, review the documentation on
  * https://developers.google.com/places/web-service/search#TextSearchRequests
  * for further information about the expected results.
  *
  * @param string $query Text query
  * @param array $params parameters for the request. These override [GeocodingRequest::params].
  *
  * @return mixed|null
  * @throws \yii\base\InvalidConfigException
  */
 public function findPlaces($query, $params = [])
 {
     $params['query'] = $query;
     $this->params = ArrayHelper::merge($this->params, $params);
     return parent::request();
 }
 /**
  * Makes a reverse geocoding by coordinates
  *
  * @param LatLng $coord
  * @param array $params parameters for the request. These override [GeocodingRequest::params].
  * @return mixed|null
  */
 public function reverse(LatLng $coord, $params = [])
 {
     $params['latlng'] = $coord;
     $this->params = ArrayHelper::merge($this->params, $params);
     return parent::request();
 }
 /**
  * Makes elevation request by paths
  *
  * @param \dosamigos\google\maps\LatLng[] $coords defines a path on the earth for which to return elevation data.
  * @param int $samples specifies the number of sample points along a path for which to return the elevation data.
  * @param bool $encode
  *
  * @return mixed|null
  */
 public function byPath($coords, $samples, $encode = true)
 {
     $this->params['path'] = $encode ? Encoder::encodeCoordinates($coords) : implode('|', $coords);
     $this->params['samples'] = $samples;
     return parent::request();
 }
 /**
  * Makes a request for place details. Please, review the documentation on
  * https://developers.google.com/places/web-service/details#PlaceDetailsResponses
  * for further information about the expected results.
  *
  * @param string $placeId Place ID
  * @param array $params parameters for the request. These override [GeocodingRequest::params].
  *
  * @return mixed|null
  * @throws \yii\base\InvalidConfigException
  */
 public function getDetails($placeId, $params = [])
 {
     $params['placeid'] = $placeId;
     $this->params = ArrayHelper::merge($this->params, $params);
     return parent::request();
 }