Geocoder\Provider\GoogleMaps::geocode PHP Method

geocode() public method

{@inheritDoc}
public geocode ( $address )
    public function geocode($address)
    {
        // Google API returns invalid data if IP address given
        // This API doesn't handle IPs
        if (filter_var($address, FILTER_VALIDATE_IP)) {
            throw new UnsupportedOperation('The GoogleMaps provider does not support IP addresses, only street addresses.');
        }
        $query = sprintf($this->useSsl ? self::ENDPOINT_URL_SSL : self::ENDPOINT_URL, rawurlencode($address));
        return $this->executeQuery($query);
    }

Usage Example

 /**
  * @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();
 }
All Usage Examples Of Geocoder\Provider\GoogleMaps::geocode