@@ -34,6 +34,8 @@ require_once('path/to/vendor/autoload.php');
3434#### Resolving an address
3535
3636``` {php}
37+ use CommonException;
38+
3739try{
3840 // Perform lookup
3941 $addressLookup = new GoogleGeocode\AddressLookup();
4850 // Retrieving the first lookup result as GoogleGeocode\GeoLookupResult instance
4951 $firstResult = $addressLookup->getFirstResult();
5052
51- } catch (GoogleGeocode\Exception\ NetworkException $exception) {
53+ } catch (CommonException\ NetworkException\CurlException $exception) {
5254 // Google Geocode API is not reachable or curl failed
53- } catch (GoogleGeocode\Exception\ ApiException $exception) {
55+ } catch (CommonException\ ApiException\InvalidResponseException $exception) {
5456 // Google Geocode API unexpected result
55- } catch (GoogleGeocode\Exception\ApiLimitException $exception) {
57+ } catch (CommonException\ApiException\RequestQuotaException $exception) {
5658 // Google Geocode API requests over the allowed limit
57- } catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
59+ } catch (CommonException\ApiException\NoResultException $exception) {
5860 // Google Geocode API request had no result
5961}
6062
6365#### Resolving a geo location
6466
6567``` {php}
68+ use CommonException;
69+
6670try{
6771 // Perform lookup
6872 $geoLocationLookup = new GoogleGeocode\GeoLocationLookup();
7781 // Retrieving the first lookup result as GoogleGeocode\AddressLookupResult instance
7882 $firstResult = $geoLocationLookup->getFirstResult();
7983
80- } catch (GoogleGeocode\Exception\ NetworkException $exception) {
84+ } catch (CommonException\ NetworkException\CurlException $exception) {
8185 // Google Geocode API is not reachable or curl failed
82- } catch (GoogleGeocode\Exception\ ApiException $exception) {
86+ } catch (CommonException\ ApiException\InvalidResponseException $exception) {
8387 // Google Geocode API unexpected result
84- } catch (GoogleGeocode\Exception\ApiLimitException $exception) {
88+ } catch (CommonException\ApiException\RequestQuotaException $exception) {
8589 // Google Geocode API requests over the allowed limit
86- } catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
90+ } catch (CommonException\ApiException\NoResultException $exception) {
8791 // Google Geocode API request had no result
8892}
8993
9498Resolving Google Places IDs utilizes the Google Places API. Therefore a Places API key is mandatory for performing a lookup. Please visit the [ Google API console] ( https://console.developers.google.com/apis/api/geocoding_backend?project=_ ) to receive an API key.
9599
96100``` {php}
101+ use CommonException;
102+
97103try{
98104 // Perform lookup
99105 $googlePlacesLookup = new GoogleGeocode\GooglePlacesLookup();
@@ -110,13 +116,15 @@ try{
110116 // Retrieving the first lookup result as GoogleGeocode\AddressLookupResult instance
111117 $firstResult = $googlePlacesLookup->getFirstResult();
112118
113- } catch (GoogleGeocode\Exception\ NetworkException $exception) {
119+ } catch (CommonException\ NetworkException\CurlException $exception) {
114120 // Google Geocode API is not reachable or curl failed
115- } catch (GoogleGeocode\Exception\ ApiException $exception) {
121+ } catch (CommonException\ ApiException\InvalidResponseException $exception) {
116122 // Google Geocode API unexpected result
117- } catch (GoogleGeocode\Exception\ApiLimitException $exception) {
123+ } catch (CommonException\ApiException\RequestQuotaException $exception) {
118124 // Google Geocode API requests over the allowed limit
119- } catch (GoogleGeocode\Exception\ApiNoResultsException $exception) {
125+ } catch (CommonException\ApiException\AuthenticationException $exception) {
126+ // Google Places service API key invalid
127+ } catch (CommonException\ApiException\NoResultException $exception) {
120128 // Google Geocode API request had no result
121129}
122130
@@ -221,6 +229,11 @@ if($firstResult->hasGooglePlacesId()) {
221229}
222230```
223231
232+ ## Exception handling
233+
234+ PHP Google Geocoder provides different exceptions provided by the PHP Common Exceptions project for proper handling.
235+ You can find more information about [ PHP Common Exceptions at Github] ( https://github.com/markenwerk/php-common-exceptions ) .
236+
224237## Contribution
225238
226239Contributing to our projects is always very appreciated.
0 commit comments