/** * Get the geocode result object from the geocoder object. * @param string $apiKey - google map api key. * @param array $geoCodeQueryData - required query data in the form of array. * @return object - geocoder result object. */ public static function getGeoCodeResultByData($apiKey, $geoCodeQueryData) { assert('$apiKey == null || is_string($apiKey)'); assert('is_array($geoCodeQueryData)'); Yii::import('application.extensions.geocoder.*'); $geoCoder = new GeoCoder(); $geoCoder->setApiKey($apiKey); $geoCoder->setApiDriver('Google'); $geoCoder->init(); $geoCodeDriver = GeoCode_Driver::factory($geoCoder->getApiDriver(), $apiKey); if ($geoCodeQueryData['latitude'] == null && $geoCodeQueryData['longitude'] == null) { $geoCodeResult = $geoCoder->query($geoCodeQueryData['query']); $geoCodeQueryData['latitude'] = $geoCodeResult->latitude; $geoCodeQueryData['longitude'] = $geoCodeResult->longitude; return new GeoCode_Result($geoCodeDriver, $geoCodeQueryData); } else { return new GeoCode_Result($geoCodeDriver, $geoCodeQueryData); } }
/** * Set the driver for the GeoCode requests * * @param string $driver * @return boolean */ public function setDriver($driver) { // Lowercase for comparisons $driver = strtolower($driver); // If this driver is the same as the current driver, skip if ($this->_driver !== null && $this->api_driver == $driver) { return true; } // Make sure the driver exists if (!empty($driver)) { // Load the new driver $this->_driver = GeoCode_Driver::factory($driver, $this->api_key); // Save the driver string $this->api_driver = $driver; return true; } return false; }