Revision: 1234
Author: christian.wuerker
Date: Tue Jun 30 18:09:08 2015 UTC
Log: Check geocoder result directly after fetching response.
https://code.google.com/p/cmclasses/source/detail?r=1234
Modified:
/trunk/src/Net/API/Google/Maps/Geocoder.php
=======================================
--- /trunk/src/Net/API/Google/Maps/Geocoder.php Sat May 23 06:45:51 2015 UTC
+++ /trunk/src/Net/API/Google/Maps/Geocoder.php Tue Jun 30 18:09:08 2015 UTC
@@ -63,6 +63,11 @@
return File_Editor::load( $cacheFile );
}
$xml = $this->sendQuery( $query );
+ $doc = new XML_Element( $xml );
+ if( $doc->status->getValue() === "OVER_QUERY_LIMIT" )
+ throw new RuntimeException( 'Query limit reached' );
+ if( !@$doc->result->geometry->location )
+ throw new InvalidArgumentException( 'Address not found' );
if( $this->pathCache )
File_Editor::save( $cacheFile, $xml );
return $xml;
@@ -74,13 +79,13 @@
* @param string $address Address to get data for
* @param bool $force Flag: do not use cache
* @return array
+ * @throws RuntimeException if query limit is reached
+ * @throws InvalidArgumentException if address could not been resolved
*/
public function getGeoTags( $address, $force = FALSE )
{
$xml = $this->getGeoCode( $address, $force );
$xml = new XML_Element( $xml );
- if( !@$xml->result->geometry->location )
- throw new RuntimeException( 'Address not found' );
$coordinates = (string) $xml->result->geometry->location;
$parts = explode( ",", $coordinates );
$data = array(