/** * Looks up the geo coordinates of the address of an object and sets its * geo coordinates. * * @param tx_oelib_Interface_Geo $geoObject * the object for which the geo coordinates will be looked up and set * * @return void */ public function lookUp(tx_oelib_Interface_Geo $geoObject) { if ($geoObject->hasGeoError() || $geoObject->hasGeoCoordinates()) { return; } if (!$geoObject->hasGeoAddress()) { $geoObject->setGeoError(); return; } if (!empty($this->coordinates)) { $geoObject->setGeoCoordinates($this->coordinates); } else { $geoObject->setGeoError(); } }
/** * Looks up the geo coordinates of the address of an object and sets its * geo coordinates. * * @param tx_oelib_Interface_Geo $geoObject * the object for which the geo coordinates will be looked up and set * * @return void */ public function lookUp(tx_oelib_Interface_Geo $geoObject) { if ($geoObject->hasGeoError() || $geoObject->hasGeoCoordinates()) { return; } if (!$geoObject->hasGeoAddress()) { $geoObject->setGeoError(); return; } $address = $geoObject->getGeoAddress(); $this->throttle(); $rawResult = $this->sendRequest($address); if ($rawResult === FALSE) { throw new RuntimeException('There was an error connecting to the Google geocoding server.', 1331488446); } $resultParts = json_decode($rawResult, TRUE); $status = $resultParts['status']; if ($status === self::STATUS_OK) { $coordinates = $resultParts['results'][0]['geometry']['location']; $geoObject->setGeoCoordinates(array('latitude' => (double) $coordinates['lat'], 'longitude' => (double) $coordinates['lng'])); } else { $geoObject->setGeoError(); } }